PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.2.06
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.2.06
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 +7 -55 6.55.2.06 View file →
@@ -12,22 +12,10 @@
12 12 * @var string
13 13 * @since 3.0
14 14 */
15 15 protected $type = 'number';
16 -
17 - /**
18 - * @var string
19 - */
20 16 protected $display_type = 'text';
21 17
22 - /**
23 - * @var bool
24 - */
25 - protected $array_allowed = false;
26 -
27 - /**
28 - * @return bool[]
29 - */
30 18 protected function field_settings_for_type() {
31 19 $settings = array(
32 20 'size' => true,
33 21 'clear_on_focus' => true,
@@ -42,11 +30,8 @@
42 30
43 31 return $settings;
44 32 }
45 33
46 - /**
47 - * @return array
48 - */
49 34 protected function extra_field_opts() {
50 35 return array(
51 36 'minnum' => 0,
52 37 'maxnum' => 9999999,
@@ -55,10 +40,8 @@
55 40 }
56 41
57 42 /**
58 43 * @since 3.01.03
59 - *
60 - * @return void
61 44 */
62 45 protected function add_extra_html_atts( $args, &$input_html ) {
63 46 $this->add_min_max( $args, $input_html );
64 47 }
@@ -100,10 +83,8 @@
100 83 * @since 5.2.06
101 84 *
102 85 * @param array $errors Errors array.
103 86 * @param array $args Validation args.
104 - *
105 - * @return void
106 87 */
107 88 private function validate_step( &$errors, $args ) {
108 89 if ( isset( $errors[ 'field' . $args['id'] ] ) ) {
109 90 return; // Don't need to check if value is invalid before.
@@ -113,56 +94,29 @@
113 94 if ( ! $step || ! is_numeric( $step ) ) {
114 95 return;
115 96 }
116 97
117 - $result = $this->check_value_is_valid_with_step( $args['value'], $step );
118 - if ( ! $result ) {
98 + $value = (float) $args['value'];
99 + $step = (float) $step;
100 + $div = $value / $step;
101 + if ( floor( $div ) === $div ) {
119 102 return;
120 103 }
121 104
105 + $div = floor( $div );
122 106 $errors[ 'field' . $args['id'] ] = sprintf(
123 107 // Translators: %1$s: the first nearest value; %2$s: the second nearest value.
124 108 __( 'Please enter a valid value. Two nearest valid values are %1$s and %2$s', 'formidable' ),
125 - floatval( $result[0] ),
126 - floatval( $result[1] )
109 + floatval( $div * $step ),
110 + floatval( ( $div + 1 ) * $step )
127 111 );
128 112 }
129 113
130 114 /**
131 - * Checks if value is valid with the given step.
132 - *
133 - * @since 5.2.07
134 - *
135 - * @param numeric $value The value.
136 - * @param numeric $step The step.
137 - * @return int|array Return `0` if valid. Otherwise, return an array contains two nearest values.
138 - */
139 - private function check_value_is_valid_with_step( $value, $step ) {
140 - // Count the number of decimals.
141 - $decimals = max( FrmAppHelper::count_decimals( $value ), FrmAppHelper::count_decimals( $step ) );
142 -
143 - // Convert value and step to int to prevent precision problem.
144 - $pow = pow( 10, $decimals );
145 - $value = intval( $pow * $value );
146 - $step = intval( $pow * $step );
147 - $div = $value / $step;
148 - if ( is_int( $div ) ) {
149 - return 0;
150 - }
151 -
152 - $div = floor( $div );
153 - return array( $div * $step / $pow, ( $div + 1 ) * $step / $pow );
154 - }
155 -
156 - /**
157 115 * IE fallback for number fields
158 116 * Remove the comma when HTML5 isn't supported
159 117 *
160 118 * @since 3.0
161 - *
162 - * @param array $args
163 - *
164 - * @return void
165 119 */
166 120 private function remove_commas_from_number( &$args ) {
167 121 if ( strpos( $args['value'], ',' ) ) {
168 122 $args['value'] = str_replace( ',', '', $args['value'] );
@@ -182,10 +136,8 @@
182 136 }
183 137
184 138 /**
185 139 * @since 4.0.04
186 - *
187 - * @return void
188 140 */
189 141 public function sanitize_value( &$value ) {
190 142 FrmAppHelper::sanitize_value( 'sanitize_text_field', $value );
191 143 }