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