PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.13
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.13
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/fields/FrmFieldNumber.php +20 -33 6.266.13 View file →
@@ -9,9 +9,8 @@
9 9 class FrmFieldNumber extends FrmFieldType {
10 10
11 11 /**
12 12 * @var string
13 - *
14 13 * @since 3.0
15 14 */
16 15 protected $type = 'number';
17 16
@@ -49,11 +48,8 @@
49 48
50 49 /**
51 50 * @since 3.01.03
52 51 *
53 - * @param array $args
54 - * @param string $input_html
55 - *
56 52 * @return void
57 53 */
58 54 protected function add_extra_html_atts( $args, &$input_html ) {
59 55 $this->add_min_max( $args, $input_html );
@@ -68,24 +64,25 @@
68 64 if ( ! is_numeric( $args['value'] ) && '' !== $args['value'] ) {
69 65 $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $this->field, 'invalid' );
70 66 }
71 67
72 - if ( $args['value'] === '' ) {
73 - return $errors;
74 - }
68 + // validate number settings
69 + if ( $args['value'] != '' ) {
70 + // only check if options are available in settings
71 + $minnum = FrmField::get_option( $this->field, 'minnum' );
72 + $maxnum = FrmField::get_option( $this->field, 'maxnum' );
73 + if ( $maxnum !== '' && $minnum !== '' ) {
74 + $value = (float) $args['value'];
75 + if ( $value < $minnum ) {
76 + $errors[ 'field' . $args['id'] ] = __( 'Please select a higher number', 'formidable' );
77 + } elseif ( $value > $maxnum ) {
78 + $errors[ 'field' . $args['id'] ] = __( 'Please select a lower number', 'formidable' );
79 + }
80 + }
75 81
76 - $value = (float) $args['value'];
77 - $minnum = FrmField::get_option( $this->field, 'minnum' );
78 - $maxnum = FrmField::get_option( $this->field, 'maxnum' );
79 -
80 - if ( $minnum !== '' && $value < $minnum ) {
81 - $errors[ 'field' . $args['id'] ] = __( 'Please select a higher number', 'formidable' );
82 - } elseif ( $maxnum !== '' && $value > $maxnum ) {
83 - $errors[ 'field' . $args['id'] ] = __( 'Please select a lower number', 'formidable' );
82 + $this->validate_step( $errors, $args );
84 83 }
85 84
86 - $this->validate_step( $errors, $args );
87 -
88 85 return $errors;
89 86 }
90 87
91 88 /**
@@ -97,9 +94,9 @@
97 94 * @param array $args Validation args.
98 95 *
99 96 * @return void
100 97 */
101 - protected function validate_step( &$errors, $args ) {
98 + private function validate_step( &$errors, $args ) {
102 99 if ( isset( $errors[ 'field' . $args['id'] ] ) ) {
103 100 // Don't need to check if value is invalid before.
104 101 return;
105 102 }
@@ -104,15 +101,13 @@
104 101 return;
105 102 }
106 103
107 104 $step = FrmField::get_option( $this->field, 'step' );
108 -
109 105 if ( ! $step || ! is_numeric( $step ) ) {
110 106 return;
111 107 }
112 108
113 109 $result = $this->check_value_is_valid_with_step( $args['value'], $step );
114 -
115 110 if ( ! $result ) {
116 111 return;
117 112 }
118 113
@@ -118,10 +113,10 @@
118 113
119 114 $errors[ 'field' . $args['id'] ] = sprintf(
120 115 // Translators: %1$s: the first nearest value; %2$s: the second nearest value.
121 116 __( 'Please enter a valid value. Two nearest valid values are %1$s and %2$s', 'formidable' ),
122 - is_numeric( $result[0] ) ? floatval( $result[0] ) : $result[0],
123 - is_numeric( $result[1] ) ? floatval( $result[1] ) : $result[1]
117 + floatval( $result[0] ),
118 + floatval( $result[1] )
124 119 );
125 120 }
126 121
127 122 /**
@@ -130,21 +125,19 @@
130 125 * @since 5.2.07
131 126 *
132 127 * @param numeric $value The value.
133 128 * @param numeric $step The step.
134 - *
135 129 * @return array|int Return `0` if valid. Otherwise, return an array contains two nearest values.
136 130 */
137 - protected function check_value_is_valid_with_step( $value, $step ) {
131 + private function check_value_is_valid_with_step( $value, $step ) {
138 132 // Count the number of decimals.
139 - $decimals = (int) max( FrmAppHelper::count_decimals( $value ), FrmAppHelper::count_decimals( $step ) );
133 + $decimals = max( FrmAppHelper::count_decimals( $value ), FrmAppHelper::count_decimals( $step ) );
140 134
141 135 // Convert value and step to int to prevent precision problem.
142 - $pow = 10 ** $decimals;
136 + $pow = pow( 10, $decimals );
143 137 $value = intval( $pow * $value );
144 138 $step = intval( $pow * $step );
145 139 $div = $value / $step;
146 -
147 140 if ( is_int( $div ) ) {
148 141 return 0;
149 142 }
150 143
@@ -170,12 +163,8 @@
170 163 }
171 164
172 165 /**
173 166 * Force the value to be numeric before it's saved in the DB
174 - *
175 - * @param array|string $value
176 - *
177 - * @return float
178 167 */
179 168 public function set_value_before_save( $value ) {
180 169 if ( ! is_numeric( $value ) ) {
181 170 $value = (float) $value;
@@ -185,10 +174,8 @@
185 174 }
186 175
187 176 /**
188 177 * @since 4.0.04
189 - *
190 - * @param array|string $value
191 178 *
192 179 * @return void
193 180 */
194 181 public function sanitize_value( &$value ) {