PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 3.06.06
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v3.06.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 +0 -94 6.53.06.06 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -if ( ! defined( 'ABSPATH' ) ) {
3 - die( 'You are not allowed to call this page directly.' );
4 -}
5 2
6 3 /**
7 4 * @since 3.0
8 5 */
@@ -12,22 +9,10 @@
12 9 * @var string
13 10 * @since 3.0
14 11 */
15 12 protected $type = 'number';
16 -
17 - /**
18 - * @var string
19 - */
20 13 protected $display_type = 'text';
21 14
22 - /**
23 - * @var bool
24 - */
25 - protected $array_allowed = false;
26 -
27 - /**
28 - * @return bool[]
29 - */
30 15 protected function field_settings_for_type() {
31 16 $settings = array(
32 17 'size' => true,
33 18 'clear_on_focus' => true,
@@ -42,11 +27,8 @@
42 27
43 28 return $settings;
44 29 }
45 30
46 - /**
47 - * @return array
48 - */
49 31 protected function extra_field_opts() {
50 32 return array(
51 33 'minnum' => 0,
52 34 'maxnum' => 9999999,
@@ -55,10 +37,8 @@
55 37 }
56 38
57 39 /**
58 40 * @since 3.01.03
59 - *
60 - * @return void
61 41 */
62 42 protected function add_extra_html_atts( $args, &$input_html ) {
63 43 $this->add_min_max( $args, $input_html );
64 44 }
@@ -86,83 +66,19 @@
86 66 } elseif ( $value > $maxnum ) {
87 67 $errors[ 'field' . $args['id'] ] = __( 'Please select a lower number', 'formidable' );
88 68 }
89 69 }
90 -
91 - $this->validate_step( $errors, $args );
92 70 }
93 71
94 72 return $errors;
95 73 }
96 74
97 - /**
98 - * Validates the step setting.
99 - *
100 - * @since 5.2.06
101 - *
102 - * @param array $errors Errors array.
103 - * @param array $args Validation args.
104 - *
105 - * @return void
106 - */
107 - private function validate_step( &$errors, $args ) {
108 - if ( isset( $errors[ 'field' . $args['id'] ] ) ) {
109 - return; // Don't need to check if value is invalid before.
110 - }
111 75
112 - $step = FrmField::get_option( $this->field, 'step' );
113 - if ( ! $step || ! is_numeric( $step ) ) {
114 - return;
115 - }
116 -
117 - $result = $this->check_value_is_valid_with_step( $args['value'], $step );
118 - if ( ! $result ) {
119 - return;
120 - }
121 -
122 - $errors[ 'field' . $args['id'] ] = sprintf(
123 - // Translators: %1$s: the first nearest value; %2$s: the second nearest value.
124 - __( 'Please enter a valid value. Two nearest valid values are %1$s and %2$s', 'formidable' ),
125 - floatval( $result[0] ),
126 - floatval( $result[1] )
127 - );
128 - }
129 -
130 76 /**
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 77 * IE fallback for number fields
158 78 * Remove the comma when HTML5 isn't supported
159 79 *
160 80 * @since 3.0
161 - *
162 - * @param array $args
163 - *
164 - * @return void
165 81 */
166 82 private function remove_commas_from_number( &$args ) {
167 83 if ( strpos( $args['value'], ',' ) ) {
168 84 $args['value'] = str_replace( ',', '', $args['value'] );
@@ -176,17 +92,7 @@
176 92 public function set_value_before_save( $value ) {
177 93 if ( ! is_numeric( $value ) ) {
178 94 $value = (float) $value;
179 95 }
180 -
181 96 return $value;
182 - }
183 -
184 - /**
185 - * @since 4.0.04
186 - *
187 - * @return void
188 - */
189 - public function sanitize_value( &$value ) {
190 - FrmAppHelper::sanitize_value( 'sanitize_text_field', $value );
191 97 }
192 98 }