| @@ -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 | |
| @@ -59,29 +67,31 @@ | ||
| 59 | 67 | $errors = array(); |
| 60 | 68 | |
| 61 | 69 | $this->remove_commas_from_number( $args ); |
| 62 | 70 | |
| 63 | - // Validate the number format. | |
| 71 | + //validate the number format | |
| 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,12 +103,11 @@ | ||
| 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 | - // Don't need to check if value is invalid before. | |
| 100 | - return; | |
| 109 | + return; // Don't need to check if value is invalid before. | |
| 101 | 110 | } |
| 102 | 111 | |
| 103 | 112 | $step = FrmField::get_option( $this->field, 'step' ); |
| 104 | 113 | if ( ! $step || ! is_numeric( $step ) ) { |
| @@ -112,10 +121,10 @@ | ||
| 112 | 121 | |
| 113 | 122 | $errors[ 'field' . $args['id'] ] = sprintf( |
| 114 | 123 | // Translators: %1$s: the first nearest value; %2$s: the second nearest value. |
| 115 | 124 | __( '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] | |
| 125 | + floatval( $result[0] ), | |
| 126 | + floatval( $result[1] ) | |
| 118 | 127 | ); |
| 119 | 128 | } |
| 120 | 129 | |
| 121 | 130 | /** |
| @@ -124,16 +133,16 @@ | ||
| 124 | 133 | * @since 5.2.07 |
| 125 | 134 | * |
| 126 | 135 | * @param numeric $value The value. |
| 127 | 136 | * @param numeric $step The step. |
| 128 | - * @return array|int Return `0` if valid. Otherwise, return an array contains two nearest values. | |
| 137 | + * @return int|array Return `0` if valid. Otherwise, return an array contains two nearest values. | |
| 129 | 138 | */ |
| 130 | - protected function check_value_is_valid_with_step( $value, $step ) { | |
| 139 | + private function check_value_is_valid_with_step( $value, $step ) { | |
| 131 | 140 | // Count the number of decimals. |
| 132 | - $decimals = (int) max( FrmAppHelper::count_decimals( $value ), FrmAppHelper::count_decimals( $step ) ); | |
| 141 | + $decimals = max( FrmAppHelper::count_decimals( $value ), FrmAppHelper::count_decimals( $step ) ); | |
| 133 | 142 | |
| 134 | 143 | // Convert value and step to int to prevent precision problem. |
| 135 | - $pow = 10 ** $decimals; | |
| 144 | + $pow = pow( 10, $decimals ); | |
| 136 | 145 | $value = intval( $pow * $value ); |
| 137 | 146 | $step = intval( $pow * $step ); |
| 138 | 147 | $div = $value / $step; |
| 139 | 148 | if ( is_int( $div ) ) { |