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