PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.8
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.8
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 +31 -21 6.256.8 View file →
@@ -14,8 +14,13 @@
14 14 */
15 15 protected $type = 'number';
16 16
17 17 /**
18 + * @var string
19 + */
20 + protected $display_type = 'text';
21 +
22 + /**
18 23 * @var bool
19 24 */
20 25 protected $array_allowed = false;
21 26
@@ -29,9 +34,12 @@
29 34 'invalid' => true,
30 35 'range' => true,
31 36 );
32 37
33 - $settings['max'] = false;
38 + $frm_settings = FrmAppHelper::get_settings();
39 + if ( $frm_settings->use_html ) {
40 + $settings['max'] = false;
41 + }
34 42
35 43 return $settings;
36 44 }
37 45
@@ -64,24 +72,26 @@
64 72 if ( ! is_numeric( $args['value'] ) && '' !== $args['value'] ) {
65 73 $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $this->field, 'invalid' );
66 74 }
67 75
68 - if ( $args['value'] === '' ) {
69 - return $errors;
70 - }
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 + }
71 90
72 - $value = (float) $args['value'];
73 - $minnum = FrmField::get_option( $this->field, 'minnum' );
74 - $maxnum = FrmField::get_option( $this->field, 'maxnum' );
75 -
76 - if ( $minnum !== '' && $value < $minnum ) {
77 - $errors[ 'field' . $args['id'] ] = __( 'Please select a higher number', 'formidable' );
78 - } elseif ( $maxnum !== '' && $value > $maxnum ) {
79 - $errors[ 'field' . $args['id'] ] = __( 'Please select a lower number', 'formidable' );
91 + $this->validate_step( $errors, $args );
80 92 }
81 93
82 - $this->validate_step( $errors, $args );
83 -
84 94 return $errors;
85 95 }
86 96
87 97 /**
@@ -93,9 +103,9 @@
93 103 * @param array $args Validation args.
94 104 *
95 105 * @return void
96 106 */
97 - protected function validate_step( &$errors, $args ) {
107 + private function validate_step( &$errors, $args ) {
98 108 if ( isset( $errors[ 'field' . $args['id'] ] ) ) {
99 109 // Don't need to check if value is invalid before.
100 110 return;
101 111 }
@@ -112,10 +122,10 @@
112 122
113 123 $errors[ 'field' . $args['id'] ] = sprintf(
114 124 // Translators: %1$s: the first nearest value; %2$s: the second nearest value.
115 125 __( 'Please enter a valid value. Two nearest valid values are %1$s and %2$s', 'formidable' ),
116 - is_numeric( $result[0] ) ? floatval( $result[0] ) : $result[0],
117 - is_numeric( $result[1] ) ? floatval( $result[1] ) : $result[1]
126 + floatval( $result[0] ),
127 + floatval( $result[1] )
118 128 );
119 129 }
120 130
121 131 /**
@@ -124,16 +134,16 @@
124 134 * @since 5.2.07
125 135 *
126 136 * @param numeric $value The value.
127 137 * @param numeric $step The step.
128 - * @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.
129 139 */
130 - protected function check_value_is_valid_with_step( $value, $step ) {
140 + private function check_value_is_valid_with_step( $value, $step ) {
131 141 // Count the number of decimals.
132 - $decimals = (int) max( FrmAppHelper::count_decimals( $value ), FrmAppHelper::count_decimals( $step ) );
142 + $decimals = max( FrmAppHelper::count_decimals( $value ), FrmAppHelper::count_decimals( $step ) );
133 143
134 144 // Convert value and step to int to prevent precision problem.
135 - $pow = 10 ** $decimals;
145 + $pow = pow( 10, $decimals );
136 146 $value = intval( $pow * $value );
137 147 $step = intval( $pow * $step );
138 148 $div = $value / $step;
139 149 if ( is_int( $div ) ) {