PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.18
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.18
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 +10 -25 6.336.18 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 );
@@ -58,11 +54,8 @@
58 54 protected function add_extra_html_atts( $args, &$input_html ) {
59 55 $this->add_min_max( $args, $input_html );
60 56 }
61 57
62 - /**
63 - * @param array $args
64 - */
65 58 public function validate( $args ) {
66 59 $errors = array();
67 60
68 61 $this->remove_commas_from_number( $args );
@@ -107,15 +100,13 @@
107 100 return;
108 101 }
109 102
110 103 $step = FrmField::get_option( $this->field, 'step' );
111 -
112 104 if ( ! $step || ! is_numeric( $step ) ) {
113 105 return;
114 106 }
115 107
116 108 $result = $this->check_value_is_valid_with_step( $args['value'], $step );
117 -
118 109 if ( ! $result ) {
119 110 return;
120 111 }
121 112
@@ -133,21 +124,19 @@
133 124 * @since 5.2.07
134 125 *
135 126 * @param numeric $value The value.
136 127 * @param numeric $step The step.
137 - *
138 128 * @return array|int Return `0` if valid. Otherwise, return an array contains two nearest values.
139 129 */
140 130 protected function check_value_is_valid_with_step( $value, $step ) {
141 131 // Count the number of decimals.
142 - $decimals = (int) max( FrmAppHelper::count_decimals( $value ), FrmAppHelper::count_decimals( $step ) );
132 + $decimals = max( FrmAppHelper::count_decimals( $value ), FrmAppHelper::count_decimals( $step ) );
143 133
144 134 // Convert value and step to int to prevent precision problem.
145 - $pow = 10 ** $decimals;
135 + $pow = pow( 10, $decimals );
146 136 $value = intval( $pow * $value );
147 137 $step = intval( $pow * $step );
148 138 $div = $value / $step;
149 -
150 139 if ( is_int( $div ) ) {
151 140 return 0;
152 141 }
153 142
@@ -165,31 +154,27 @@
165 154 *
166 155 * @return void
167 156 */
168 157 private function remove_commas_from_number( &$args ) {
169 - if ( ! str_contains( $args['value'], ',' ) ) {
170 - return;
158 + if ( strpos( $args['value'], ',' ) ) {
159 + $args['value'] = str_replace( ',', '', $args['value'] );
160 + FrmEntriesHelper::set_posted_value( $this->field, $args['value'], $args );
171 161 }
172 -
173 - $args['value'] = str_replace( ',', '', $args['value'] );
174 - FrmEntriesHelper::set_posted_value( $this->field, $args['value'], $args );
175 162 }
176 163
177 164 /**
178 165 * Force the value to be numeric before it's saved in the DB
179 - *
180 - * @param array|string $value
181 - *
182 - * @return float
183 166 */
184 167 public function set_value_before_save( $value ) {
185 - return is_numeric( $value ) ? $value : (float) $value;
168 + if ( ! is_numeric( $value ) ) {
169 + $value = (float) $value;
170 + }
171 +
172 + return $value;
186 173 }
187 174
188 175 /**
189 176 * @since 4.0.04
190 - *
191 - * @param array|string $value
192 177 *
193 178 * @return void
194 179 */
195 180 public function sanitize_value( &$value ) {