PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 3.5.2
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v3.5.2
3.5.2 3.5.1 3.5.0 3.4.8 3.4.7 3.4.6 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5.1 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.10 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.6.1 1.6.7 1.7.0 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.2 1.7.2.1 1.7.2.2 1.7.3 1.7.4 1.7.5 1.7.5.1 1.7.5.2 1.7.6 1.7.7 1.7.7.1 1.7.7.2 1.7.8 1.7.9 1.8.0 1.8.0.1 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.0.1 1.9.1 1.9.2 1.9.3 1.9.4 1.9.4.1 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.0.1 2.0.1 2.0.2 2.0.3 2.0.3.1 2.0.4 2.0.4.1 2.0.5 2.0.6 2.0.7 2.0.8 2.0.8.1 2.0.9 3.0.0 3.0.0.1 3.0.1 3.0.2 3.0.3 3.0.3.1 3.0.4 3.0.4.1 3.0.4.2 3.0.5 3.0.5.1 3.0.5.2 3.0.6 3.0.6.1 3.0.7.1 3.0.8 3.0.8.1 3.0.9 3.0.9.1 3.0.9.2 3.0.9.3 3.0.9.4 3.0.9.5 3.1.0 3.1.1 3.1.2 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.3.0 3.4.0 3.4.1 3.4.2 3.4.2.1 3.4.3 3.4.4 3.4.5 trunk 1.0 1.0.1 1.0.2 1.0.3
everest-forms / includes / fields / class-evf-field-number.php
everest-forms / includes / fields Last commit date
class-evf-field-address.php 1 year ago class-evf-field-ai.php 1 year ago class-evf-field-captcha.php 4 weeks ago class-evf-field-checkbox.php 2 months ago class-evf-field-color.php 4 weeks ago class-evf-field-country.php 2 months ago class-evf-field-credit-card.php 4 weeks ago class-evf-field-date-time.php 4 weeks ago class-evf-field-divider.php 2 years ago class-evf-field-email.php 1 year ago class-evf-field-file-upload.php 1 year ago class-evf-field-first-name.php 1 year ago class-evf-field-hcaptcha.php 4 months ago class-evf-field-hidden.php 1 year ago class-evf-field-html.php 9 months ago class-evf-field-image-upload.php 1 year ago class-evf-field-last-name.php 1 year ago class-evf-field-likert.php 1 year ago class-evf-field-lookup.php 4 weeks ago class-evf-field-number.php 1 year ago class-evf-field-password.php 4 weeks ago class-evf-field-payment-authorize-net.php 4 weeks ago class-evf-field-payment-checkbox.php 4 weeks ago class-evf-field-payment-coupon.php 4 weeks ago class-evf-field-payment-gateway-selector.php 4 weeks ago class-evf-field-payment-quantity.php 4 weeks ago class-evf-field-payment-radio.php 4 weeks ago class-evf-field-payment-single.php 4 weeks ago class-evf-field-payment-square.php 1 year ago class-evf-field-payment-subscription-plan.php 4 weeks ago class-evf-field-payment-subtotal.php 4 weeks ago class-evf-field-payment-total.php 4 weeks ago class-evf-field-phone.php 1 year ago class-evf-field-privacy-policy.php 2 months ago class-evf-field-private-note.php 1 year ago class-evf-field-progress.php 4 weeks ago class-evf-field-radio.php 2 months ago class-evf-field-range-slider.php 4 weeks ago class-evf-field-rating.php 2 months ago class-evf-field-recaptcha.php 4 months ago class-evf-field-repeater.php 4 weeks ago class-evf-field-reset.php 4 weeks ago class-evf-field-scale-rating.php 1 year ago class-evf-field-select.php 1 year ago class-evf-field-signature.php 4 weeks ago class-evf-field-text.php 1 year ago class-evf-field-textarea.php 1 year ago class-evf-field-title.php 2 years ago class-evf-field-turnstile.php 4 months ago class-evf-field-url.php 1 year ago class-evf-field-wysiwyg.php 2 months ago class-evf-field-yes-no.php 1 year ago payment-amount-helpers.php 4 weeks ago
class-evf-field-number.php
347 lines
1 <?php
2 /**
3 * Number field.
4 *
5 * @package EverestForms\Fields
6 * @since 1.0.0
7 */
8
9 defined( 'ABSPATH' ) || exit;
10
11 /**
12 * EVF_Field_Number class.
13 */
14 class EVF_Field_Number extends EVF_Form_Fields {
15
16 /**
17 * Constructor.
18 */
19 public function __construct() {
20 $this->name = esc_html__( 'Number', 'everest-forms' );
21 $this->type = 'number';
22 $this->icon = 'evf-icon evf-icon-number';
23 $this->order = 80;
24 $this->group = 'general';
25 $this->settings = array(
26 'basic-options' => array(
27 'field_options' => array(
28 'label',
29 'description',
30 'required',
31 'required_field_message_setting',
32 'required_field_message',
33 ),
34 ),
35 'advanced-options' => array(
36 'field_options' => array(
37 'meta',
38 'step',
39 'min_value',
40 'max_value',
41 'default_value',
42 'placeholder',
43 'label_hide',
44 'css',
45 'regex_validation',
46 'regex_value',
47 'regex_message',
48 ),
49 ),
50 );
51
52 parent::__construct();
53 }
54
55 /**
56 * Hook in tabs.
57 */
58 public function init_hooks() {
59 add_filter( 'everest_forms_field_properties_' . $this->type, array( $this, 'field_properties' ), 5, 3 );
60 add_filter( 'everest_forms_field_exporter_' . $this->type, array( $this, 'field_exporter' ) );
61 }
62
63 /**
64 * Step field option.
65 *
66 * @since 1.4.9
67 * @param array $field Field Data.
68 */
69 public function step( $field ) {
70 $label = $this->field_element(
71 'label',
72 $field,
73 array(
74 'slug' => 'step',
75 'value' => esc_html__( 'Step', 'everest-forms' ),
76 'tooltip' => esc_html__( 'Allows users to enter specific legal number intervals.', 'everest-forms' ),
77 ),
78 false
79 );
80 $input_field = $this->field_element(
81 'text',
82 $field,
83 array(
84 'type' => 'number',
85 'slug' => 'step',
86 'class' => 'evf-input-number-step',
87 'value' => isset( $field['step'] ) ? $field['step'] : 0,
88 ),
89 false
90 );
91 $this->field_element(
92 'row',
93 $field,
94 array(
95 'slug' => 'step',
96 'content' => $label . $input_field,
97 )
98 );
99 }
100
101 /**
102 * Minimum value field option.
103 *
104 * @since 1.4.9
105 * @param array $field Field Data.
106 */
107 public function min_value( $field ) {
108 $label = $this->field_element(
109 'label',
110 $field,
111 array(
112 'slug' => 'min_value',
113 'value' => esc_html__( 'Min Value', 'everest-forms' ),
114 'tooltip' => esc_html__( 'Minimum value user is allowed to enter.', 'everest-forms' ),
115 ),
116 false
117 );
118 $input_field = $this->field_element(
119 'text',
120 $field,
121 array(
122 'type' => 'number',
123 'slug' => 'min_value',
124 'class' => 'evf-input-number',
125 'value' => isset( $field['min_value'] ) ? $field['min_value'] : '',
126 ),
127 false
128 );
129 $this->field_element(
130 'row',
131 $field,
132 array(
133 'slug' => 'min_value',
134 'content' => $label . $input_field,
135 )
136 );
137 }
138
139 /**
140 * Maximum value field option.
141 *
142 * @since 1.4.9
143 * @param array $field Field Data.
144 */
145 public function max_value( $field ) {
146 $label = $this->field_element(
147 'label',
148 $field,
149 array(
150 'slug' => 'max_value',
151 'value' => esc_html__( 'Max Value', 'everest-forms' ),
152 'tooltip' => esc_html__( 'Maximum value user is allowed to enter.', 'everest-forms' ),
153 ),
154 false
155 );
156 $input_field = $this->field_element(
157 'text',
158 $field,
159 array(
160 'type' => 'number',
161 'slug' => 'max_value',
162 'class' => 'evf-input-number',
163 'value' => isset( $field['max_value'] ) ? $field['max_value'] : '',
164 ),
165 false
166 );
167 $this->field_element(
168 'row',
169 $field,
170 array(
171 'slug' => 'max_value',
172 'content' => $label . $input_field,
173 )
174 );
175 }
176
177 /**
178 * Define additional field properties.
179 *
180 * @since 1.0.0
181 *
182 * @param array $properties Field properties.
183 * @param array $field Field settings.
184 * @param array $form_data Form data and settings.
185 *
186 * @return array of additional field properties.
187 */
188 public function field_properties( $properties, $field, $form_data ) {
189 // Input primary: step interval.
190 if ( ! empty( $field['step'] ) ) {
191 $properties['inputs']['primary']['attr']['step'] = (float) $field['step'];
192 }
193
194 // Input primary: minimum value.
195 if ( isset( $field['min_value'] ) && $field['min_value'] !== '' ) {
196 $properties['inputs']['primary']['attr']['min'] = ( '0' === $field['min_value'] ) ? '0' : (float) $field['min_value'];
197 }
198
199 // Input primary: maximum value.
200 if ( ! empty( $field['max_value'] ) ) {
201 $properties['inputs']['primary']['attr']['max'] = (float) $field['max_value'];
202 }
203
204 return $properties;
205 }
206
207
208 /**
209 * Filter callback for outputting formatted data.
210 *
211 * @param array $field Field Data.
212 * @return array Data for field exporter PDF or Email.
213 */
214 public function field_exporter( $field ) {
215 return array(
216 'label' => ! empty( $field['name'] ) ? $field['name'] : ucfirst( str_replace( '_', ' ', $field['type'] ) ) . " - {$field['id']}",
217 'value' => ! empty( $field['value'] ) || is_numeric( $field['value'] ) ? sanitize_text_field( $field['value'] ) : false,
218 );
219 }
220
221 /**
222 * Field preview inside the builder.
223 *
224 * @since 1.0.0
225 *
226 * @param array $field Field data and settings.
227 */
228 public function field_preview( $field ) {
229
230 // Define data.
231 $placeholder = ! empty( $field['placeholder'] ) ? esc_attr( $field['placeholder'] ) : '';
232
233 // Label.
234 $this->field_preview_option( 'label', $field );
235
236 // Primary input.
237 echo '<input type="number" placeholder="' . esc_attr($placeholder) . '" class="widefat" disabled>'; // @codingStandardsIgnoreLine.
238
239 // Description.
240 $this->field_preview_option( 'description', $field );
241 }
242
243 /**
244 * Field display on the form front-end.
245 *
246 * @since 1.0.0
247 *
248 * @param array $field Field Data.
249 * @param array $field_atts Field attributes.
250 * @param array $form_data All Form Data.
251 */
252 public function field_display( $field, $field_atts, $form_data ) {
253 // Define data.
254 $primary = $field['properties']['inputs']['primary'];
255
256 // Primary field.
257 printf(
258 '<input type="number" %s %s/>',
259 evf_html_attributes( $primary['id'], $primary['class'], $primary['data'], $primary['attr'] ),
260 esc_attr( $primary['required'] )
261 );
262 }
263
264 /**
265 * Formats and sanitizes field.
266 *
267 * @param string $field_id Field Id.
268 * @param array $field_submit Submitted Field.
269 * @param array $form_data All Form Data.
270 * @param string $meta_key Field Meta Key.
271 */
272 public function format( $field_id, $field_submit, $form_data, $meta_key ) {
273 // Define data.
274 $name = ! empty( $form_data['form_fields'][ $field_id ]['label'] ) ? $form_data['form_fields'][ $field_id ]['label'] : '';
275 $value = preg_replace( '/[^0-9.]/', '', $field_submit );
276
277 // Set final field details.
278 evf()->task->form_fields[ $field_id ] = array(
279 'name' => make_clickable( $name ),
280 'value' => sanitize_text_field( $value ),
281 'id' => $field_id,
282 'type' => $this->type,
283 'meta_key' => $meta_key,
284 );
285 }
286
287 /**
288 * Validates field for minimum and maximum data input.
289 *
290 * @since 1.4.9
291 * @param string $field_id Field Id.
292 * @param array $field_submit Submitted Data.
293 * @param array $form_data All Form Data.
294 */
295 public function validate( $field_id, $field_submit, $form_data ) {
296 $form_id = absint( $form_data['id'] );
297 $min_value = isset( $form_data['form_fields'][ $field_id ]['min_value'] ) ? floatval( $form_data['form_fields'][ $field_id ]['min_value'] ) : 0;
298 $max_value = isset( $form_data['form_fields'][ $field_id ]['max_value'] ) ? floatval( $form_data['form_fields'][ $field_id ]['max_value'] ) : 0;
299 $entry = $form_data['entry'];
300 $visible = apply_filters( 'everest_forms_visible_fields', true, $form_data['form_fields'][ $field_id ], $entry, $form_data );
301 $field_type = isset( $form_data['form_fields'][ $field_id ]['type'] ) ? $form_data['form_fields'][ $field_id ]['type'] : '';
302 $required_message = isset( $form_data['form_fields'][ $field_id ]['required-field-message'], $form_data['form_fields'][ $field_id ]['required_field_message_setting'] ) && ! empty( $form_data['form_fields'][ $field_id ]['required-field-message'] ) && 'individual' == $form_data['form_fields'][ $field_id ]['required_field_message_setting'] ? $form_data['form_fields'][ $field_id ]['required-field-message'] : get_option( 'everest_forms_' . $field_type . '_validation' );
303 if ( false === $visible ) {
304 return;
305 }
306
307 // Basic required check - If field is marked as required, check for entry data.
308 if ( ! empty( $form_data['form_fields'][ $field_id ]['required'] ) && empty( $field_submit ) && '0' !== $field_submit ) {
309 evf()->task->errors[ $form_id ][ $field_id ] = $required_message;
310 update_option( 'evf_validation_error', 'yes' );
311 }
312
313 // Check if value is numeric.
314 if ( ! empty( $field_submit ) && ! is_numeric( $field_submit ) ) {
315 evf()->task->errors[ $form_id ][ $field_id ] = apply_filters( 'everest_forms_valid_number_label', esc_html__( 'Please enter a valid number.', 'everest-forms' ) );
316 update_option( 'evf_validation_error', 'yes' );
317 }
318
319 // Check if minimum and maximum value is valid.
320 if ( ! empty( $form_data['form_fields'][ $field_id ]['min_value'] ) && ! empty( $field_submit ) && floatval( $field_submit ) < $min_value ) {
321 /* translators: %s - minimum value. */
322 evf()->task->errors[ $form_id ][ $field_id ] = sprintf( esc_html__( 'Please enter a value greater than or equal to %s', 'everest-forms' ), absint( $min_value ) );
323 update_option( 'evf_validation_error', 'yes' );
324 } elseif ( ! empty( $form_data['form_fields'][ $field_id ]['max_value'] ) && ! empty( $field_submit ) && floatval( $field_submit ) > $max_value ) {
325 /* translators: %s - maximum value. */
326 evf()->task->errors[ $form_id ][ $field_id ] = sprintf( esc_html__( 'Please enter a value less than or equal to %s', 'everest-forms' ), absint( $max_value ) );
327 update_option( 'evf_validation_error', 'yes' );
328 }
329
330 // validate regex validation.
331 if ( isset( $form_data['form_fields'][ $field_id ]['enable_regex_validation'] ) && '1' === $form_data['form_fields'][ $field_id ]['enable_regex_validation'] ) {
332 $regex_value = ! empty( $form_data['form_fields'][ $field_id ]['regex_value'] ) ? $form_data['form_fields'][ $field_id ]['regex_value'] : '';
333 $regex_message = ! empty( $form_data['form_fields'][ $field_id ]['regex_message'] ) ? $form_data['form_fields'][ $field_id ]['regex_message'] : esc_html__( 'Please provide a valid value for this field', 'everest-forms' );
334 $value = '';
335 if ( is_array( $field_submit ) ) {
336 $value = ! empty( $field_submit['primary'] ) ? $field_submit['primary'] : '';
337 } else {
338 $value = ! empty( $field_submit ) ? $field_submit : '';
339 }
340 if ( ! preg_match( '/' . $regex_value . '/', $value ) ) {
341 evf()->task->errors[ $form_data['id'] ][ $field_id ] = $regex_message;
342 update_option( 'evf_validation_error', 'yes' );
343 }
344 }
345 }
346 }
347