PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.7.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.7.2
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 +32 -36 6.276.7.2 View file →
@@ -9,14 +9,18 @@
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
18 17 /**
18 + * @var string
19 + */
20 + protected $display_type = 'text';
21 +
22 + /**
19 23 * @var bool
20 24 */
21 25 protected $array_allowed = false;
22 26
@@ -30,9 +34,12 @@
30 34 'invalid' => true,
31 35 'range' => true,
32 36 );
33 37
34 - $settings['max'] = false;
38 + $frm_settings = FrmAppHelper::get_settings();
39 + if ( $frm_settings->use_html ) {
40 + $settings['max'] = false;
41 + }
35 42
36 43 return $settings;
37 44 }
38 45
@@ -49,11 +56,8 @@
49 56
50 57 /**
51 58 * @since 3.01.03
52 59 *
53 - * @param array $args
54 - * @param string $input_html
55 - *
56 60 * @return void
57 61 */
58 62 protected function add_extra_html_atts( $args, &$input_html ) {
59 63 $this->add_min_max( $args, $input_html );
@@ -68,24 +72,26 @@
68 72 if ( ! is_numeric( $args['value'] ) && '' !== $args['value'] ) {
69 73 $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $this->field, 'invalid' );
70 74 }
71 75
72 - if ( $args['value'] === '' ) {
73 - return $errors;
74 - }
76 + // validate number settings
77 + if ( $args['value'] != '' ) {
78 + $frm_settings = FrmAppHelper::get_settings();
79 + // only check if options are available in settings
80 + $minnum = FrmField::get_option( $this->field, 'minnum' );
81 + $maxnum = FrmField::get_option( $this->field, 'maxnum' );
82 + if ( $frm_settings->use_html && $maxnum !== '' && $minnum !== '' ) {
83 + $value = (float) $args['value'];
84 + if ( $value < $minnum ) {
85 + $errors[ 'field' . $args['id'] ] = __( 'Please select a higher number', 'formidable' );
86 + } elseif ( $value > $maxnum ) {
87 + $errors[ 'field' . $args['id'] ] = __( 'Please select a lower number', 'formidable' );
88 + }
89 + }
75 90
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' );
91 + $this->validate_step( $errors, $args );
84 92 }
85 93
86 - $this->validate_step( $errors, $args );
87 -
88 94 return $errors;
89 95 }
90 96
91 97 /**
@@ -97,9 +103,9 @@
97 103 * @param array $args Validation args.
98 104 *
99 105 * @return void
100 106 */
101 - protected function validate_step( &$errors, $args ) {
107 + private function validate_step( &$errors, $args ) {
102 108 if ( isset( $errors[ 'field' . $args['id'] ] ) ) {
103 109 // Don't need to check if value is invalid before.
104 110 return;
105 111 }
@@ -104,15 +110,13 @@
104 110 return;
105 111 }
106 112
107 113 $step = FrmField::get_option( $this->field, 'step' );
108 -
109 114 if ( ! $step || ! is_numeric( $step ) ) {
110 115 return;
111 116 }
112 117
113 118 $result = $this->check_value_is_valid_with_step( $args['value'], $step );
114 -
115 119 if ( ! $result ) {
116 120 return;
117 121 }
118 122
@@ -118,10 +122,10 @@
118 122
119 123 $errors[ 'field' . $args['id'] ] = sprintf(
120 124 // Translators: %1$s: the first nearest value; %2$s: the second nearest value.
121 125 __( '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]
126 + floatval( $result[0] ),
127 + floatval( $result[1] )
124 128 );
125 129 }
126 130
127 131 /**
@@ -130,21 +134,19 @@
130 134 * @since 5.2.07
131 135 *
132 136 * @param numeric $value The value.
133 137 * @param numeric $step The step.
134 - *
135 - * @return array|int Return `0` if valid. Otherwise, return an array contains two nearest values.
138 + * @return int|array Return `0` if valid. Otherwise, return an array contains two nearest values.
136 139 */
137 - protected function check_value_is_valid_with_step( $value, $step ) {
140 + private function check_value_is_valid_with_step( $value, $step ) {
138 141 // Count the number of decimals.
139 - $decimals = (int) max( FrmAppHelper::count_decimals( $value ), FrmAppHelper::count_decimals( $step ) );
142 + $decimals = max( FrmAppHelper::count_decimals( $value ), FrmAppHelper::count_decimals( $step ) );
140 143
141 144 // Convert value and step to int to prevent precision problem.
142 - $pow = 10 ** $decimals;
145 + $pow = pow( 10, $decimals );
143 146 $value = intval( $pow * $value );
144 147 $step = intval( $pow * $step );
145 148 $div = $value / $step;
146 -
147 149 if ( is_int( $div ) ) {
148 150 return 0;
149 151 }
150 152
@@ -162,9 +164,9 @@
162 164 *
163 165 * @return void
164 166 */
165 167 private function remove_commas_from_number( &$args ) {
166 - if ( str_contains( $args['value'], ',' ) ) {
168 + if ( strpos( $args['value'], ',' ) ) {
167 169 $args['value'] = str_replace( ',', '', $args['value'] );
168 170 FrmEntriesHelper::set_posted_value( $this->field, $args['value'], $args );
169 171 }
170 172 }
@@ -170,12 +172,8 @@
170 172 }
171 173
172 174 /**
173 175 * Force the value to be numeric before it's saved in the DB
174 - *
175 - * @param array|string $value
176 - *
177 - * @return float
178 176 */
179 177 public function set_value_before_save( $value ) {
180 178 if ( ! is_numeric( $value ) ) {
181 179 $value = (float) $value;
@@ -185,10 +183,8 @@
185 183 }
186 184
187 185 /**
188 186 * @since 4.0.04
189 - *
190 - * @param array|string $value
191 187 *
192 188 * @return void
193 189 */
194 190 public function sanitize_value( &$value ) {