PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 1.9.9
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v1.9.9
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-email.php
everest-forms / includes / fields Last commit date
class-evf-field-address.php 7 years ago class-evf-field-captcha.php 6 years ago class-evf-field-checkbox.php 3 years ago class-evf-field-color.php 3 years ago class-evf-field-country.php 7 years ago class-evf-field-credit-card.php 7 years ago class-evf-field-date-time.php 3 years ago class-evf-field-divider.php 4 years ago class-evf-field-email.php 3 years ago class-evf-field-file-upload.php 6 years ago class-evf-field-first-name.php 3 years ago class-evf-field-hidden.php 7 years ago class-evf-field-html.php 7 years ago class-evf-field-image-upload.php 7 years ago class-evf-field-last-name.php 3 years ago class-evf-field-likert.php 7 years ago class-evf-field-number.php 3 years ago class-evf-field-password.php 7 years ago class-evf-field-payment-checkbox.php 7 years ago class-evf-field-payment-coupon.php 4 years ago class-evf-field-payment-quantity.php 5 years ago class-evf-field-payment-radio.php 7 years ago class-evf-field-payment-single.php 7 years ago class-evf-field-payment-subtotal.php 3 years ago class-evf-field-payment-total.php 6 years ago class-evf-field-phone.php 7 years ago class-evf-field-privacy-policy.php 4 years ago class-evf-field-progress.php 3 years ago class-evf-field-radio.php 3 years ago class-evf-field-range-slider.php 6 years ago class-evf-field-rating.php 7 years ago class-evf-field-repeater.php 4 years ago class-evf-field-reset.php 3 years ago class-evf-field-scale-rating.php 7 years ago class-evf-field-select.php 3 years ago class-evf-field-signature.php 7 years ago class-evf-field-text.php 3 years ago class-evf-field-textarea.php 3 years ago class-evf-field-title.php 6 years ago class-evf-field-url.php 3 years ago class-evf-field-wysiwyg.php 4 years ago class-evf-field-yes-no.php 3 years ago
class-evf-field-email.php
449 lines
1 <?php
2 /**
3 * Email 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_Email extends EVF_Form_Fields {
15
16 /**
17 * Constructor.
18 */
19 public function __construct() {
20 $this->name = esc_html__( 'Email', 'everest-forms' );
21 $this->type = 'email';
22 $this->icon = 'evf-icon evf-icon-email';
23 $this->order = 90;
24 $this->group = 'general';
25 $this->settings = array(
26 'basic-options' => array(
27 'field_options' => array(
28 'label',
29 'meta',
30 'description',
31 'required',
32 'required_field_message_setting',
33 'required_field_message',
34 'confirmation',
35 ),
36 ),
37 'advanced-options' => array(
38 'field_options' => array(
39 'size',
40 'placeholder',
41 'confirmation_placeholder',
42 'label_hide',
43 'sublabel_hide',
44 'default_value',
45 'css',
46 ),
47 ),
48 );
49
50 parent::__construct();
51 }
52
53 /**
54 * Hook in tabs.
55 */
56 public function init_hooks() {
57 add_filter( 'everest_forms_field_properties_' . $this->type, array( $this, 'field_properties' ), 5, 3 );
58 add_filter( 'everest_forms_field_new_required', array( $this, 'field_default_required' ), 5, 3 );
59 add_filter( 'everest_forms_builder_field_option_class', array( $this, 'field_option_class' ), 10, 2 );
60 }
61
62 /**
63 * Define additional field properties.
64 *
65 * @since 1.0.0
66 *
67 * @param array $properties Field properties.
68 * @param array $field Field settings.
69 * @param array $form_data Form data and settings.
70 *
71 * @return array of additional field properties.
72 */
73 public function field_properties( $properties, $field, $form_data ) {
74 if ( empty( $field['confirmation'] ) ) {
75 return $properties;
76 }
77
78 $form_id = absint( $form_data['id'] );
79 $field_id = $field['id'];
80
81 $props = array(
82 'inputs' => array(
83 'primary' => array(
84 'block' => array(
85 'everest-forms-field-row-block',
86 'everest-forms-one-half',
87 'everest-forms-first',
88 ),
89 'class' => array(
90 'everest-forms-field-email-primary',
91 ),
92 'sublabel' => array(
93 'hidden' => ! empty( $field['sublabel_hide'] ),
94 'value' => esc_html__( 'Email', 'everest-forms' ),
95 ),
96 ),
97 'secondary' => array(
98 'attr' => array(
99 'name' => "everest_forms[form_fields][{$field_id}][secondary]",
100 'value' => '',
101 'placeholder' => ! empty( $field['confirmation_placeholder'] ) ? evf_string_translation( $form_id, $field_id, $field['confirmation_placeholder'], '-confirm-placeholder' ) : '',
102 ),
103 'block' => array(
104 'everest-forms-field-row-block',
105 'everest-forms-one-half',
106 ),
107 'class' => array(
108 'input-text',
109 'everest-forms-field-email-secondary',
110 ),
111 'data' => array(
112 'rule-confirm' => '#' . $properties['inputs']['primary']['id'],
113 ),
114 'id' => "evf-{$form_id}-field_{$field_id}-secondary",
115 'required' => ! empty( $field['required'] ) ? 'required' : '',
116 'sublabel' => array(
117 'hidden' => ! empty( $field['sublabel_hide'] ),
118 'value' => esc_html__( 'Confirm Email', 'everest-forms' ),
119 ),
120 'value' => '',
121 ),
122 ),
123 );
124 $properties = array_merge_recursive( $properties, $props );
125
126 // Input Primary: adjust name.
127 $properties['inputs']['primary']['attr']['name'] = "everest_forms[form_fields][{$field_id}][primary]";
128
129 // Input Primary: remove error classes.
130 $properties['inputs']['primary']['class'] = array_diff(
131 $properties['inputs']['primary']['class'],
132 array(
133 'evf-error',
134 )
135 );
136
137 // Input Primary: add error class if needed.
138 if ( ! empty( $properties['error']['value']['primary'] ) ) {
139 $properties['inputs']['primary']['class'][] = 'evf-error';
140 }
141
142 // Input secondary: add error class if needed.
143 if ( ! empty( $properties['error']['value']['secondary'] ) ) {
144 $properties['inputs']['secondary']['class'][] = 'evf-error';
145 }
146
147 // Input Secondary: add required class if needed.
148 if ( ! empty( $field['required'] ) ) {
149 $properties['inputs']['secondary']['class'][] = 'evf-field-required';
150 }
151
152 return $properties;
153 }
154
155 /**
156 * Field should default to being required.
157 *
158 * @since 1.5.0
159 *
160 * @param bool $required Required status, true is required.
161 * @param array $field Field settings.
162 *
163 * @return bool
164 */
165 public function field_default_required( $required, $field ) {
166 if ( 'email' === $field['type'] ) {
167 return true;
168 }
169
170 return $required;
171 }
172
173 /**
174 * Add class to field options wrapper to indicate if field confirmation is enabled.
175 *
176 * @param array $class Field class.
177 * @param array $field Field option data.
178 * @return array
179 */
180 public function field_option_class( $class, $field ) {
181 if ( 'email' === $field['type'] ) {
182 if ( isset( $field['confirmation'] ) ) {
183 $class[] = 'everest-forms-confirm-enabled';
184 } else {
185 $class[] = 'everest-forms-confirm-disabled';
186 }
187 }
188
189 return $class;
190 }
191
192 /**
193 * Confirmation field option.
194 *
195 * @param array $field Field settings.
196 */
197 public function confirmation( $field ) {
198 $fld = $this->field_element(
199 'checkbox',
200 $field,
201 array(
202 'slug' => 'confirmation',
203 'value' => isset( $field['confirmation'] ) ? '1' : '0',
204 'desc' => esc_html__( 'Enable Email Confirmation', 'everest-forms' ),
205 'tooltip' => esc_html__( 'Check to enable email confirmation.', 'everest-forms' ),
206 ),
207 false
208 );
209 $args = array(
210 'slug' => 'confirmation',
211 'content' => $fld,
212 );
213 $this->field_element( 'row', $field, $args );
214 }
215
216 /**
217 * Confirmation Placeholder field option.
218 *
219 * @param array $field Field Data.
220 */
221 public function confirmation_placeholder( $field ) {
222 $lbl = $this->field_element(
223 'label',
224 $field,
225 array(
226 'slug' => 'confirmation_placeholder',
227 'value' => esc_html__( 'Confirmation Placeholder Text', 'everest-forms' ),
228 'tooltip' => esc_html__( 'Enter text for the confirmation field placeholder.', 'everest-forms' ),
229 ),
230 false
231 );
232 $fld = $this->field_element(
233 'text',
234 $field,
235 array(
236 'slug' => 'confirmation_placeholder',
237 'value' => ! empty( $field['confirmation_placeholder'] ) ? esc_attr( $field['confirmation_placeholder'] ) : '',
238 ),
239 false
240 );
241 $args = array(
242 'slug' => 'confirmation_placeholder',
243 'content' => $lbl . $fld,
244 );
245 $this->field_element( 'row', $field, $args );
246 }
247
248 /**
249 * Field preview inside the builder.
250 *
251 * @since 1.0.0
252 *
253 * @param array $field Field data and settings.
254 */
255 public function field_preview( $field ) {
256 $placeholder = ! empty( $field['placeholder'] ) ? esc_attr( $field['placeholder'] ) : '';
257 $confirm_placeholder = ! empty( $field['confirmation_placeholder'] ) ? esc_attr( $field['confirmation_placeholder'] ) : '';
258 $confirm = ! empty( $field['confirmation'] ) ? 'enabled' : 'disabled';
259
260 // Label.
261 $this->field_preview_option( 'label', $field );
262 ?>
263 <div class="everest-forms-confirm everest-forms-confirm-<?php echo esc_attr( $confirm ); ?>">
264 <div class="everest-forms-confirm-primary">
265 <input type="email" placeholder="<?php echo esc_attr( $placeholder ); ?>" class="widefat primary-input" disabled>
266 <label class="everest-forms-sub-label"><?php esc_html_e( 'Email', 'everest-forms' ); ?></label>
267
268 </div>
269 <div class="everest-forms-confirm-confirmation">
270 <input type="email" placeholder="<?php echo esc_attr( $confirm_placeholder ); ?>" class="widefat secondary-input" disabled>
271 <label class="everest-forms-sub-label"><?php esc_html_e( 'Confirm Email', 'everest-forms' ); ?></label>
272 </div>
273 </div>
274 <?php
275 // Description.
276 $this->field_preview_option( 'description', $field );
277 }
278
279 /**
280 * Field display on the form front-end.
281 *
282 * @since 1.0.0
283 *
284 * @param array $field Field Data.
285 * @param array $field_atts Field attributes.
286 * @param array $form_data All Form Data.
287 */
288 public function field_display( $field, $field_atts, $form_data ) {
289 // Define data.
290 $form_id = absint( $form_data['id'] );
291 $confirmation = ! empty( $field['confirmation'] );
292 $primary = $field['properties']['inputs']['primary'];
293 $secondary = ! empty( $field['properties']['inputs']['secondary'] ) ? $field['properties']['inputs']['secondary'] : '';
294
295 // Standard email field.
296 if ( ! $confirmation ) {
297
298 // Primary field.
299 printf(
300 '<input type="email" %s %s >',
301 evf_html_attributes( $primary['id'], $primary['class'], $primary['data'], $primary['attr'] ),
302 esc_attr( $primary['required'] )
303 );
304
305 // Confirmation email field configuration.
306 } else {
307
308 // Row wrapper.
309 echo '<div class="everest-forms-field-row everest-forms-field">';
310 // Primary field.
311 echo '<div ' . evf_html_attributes( false, $primary['block'] ) . '>';
312 printf(
313 '<input type="email" %s %s>',
314 evf_html_attributes( $primary['id'], $primary['class'], $primary['data'], $primary['attr'] ),
315 esc_attr( $primary['required'] )
316 );
317 $this->field_display_sublabel( 'primary', 'after', $field );
318 $this->field_display_error( 'primary', $field );
319 echo '</div>';
320
321 // Secondary field.
322 echo '<div ' . evf_html_attributes( false, $secondary['block'] ) . '>';
323 printf(
324 '<input type="email" %s %s>',
325 evf_html_attributes( $secondary['id'], $secondary['class'], $secondary['data'], $secondary['attr'] ),
326 esc_attr( $secondary['required'] )
327 );
328 $this->field_display_sublabel( 'secondary', 'after', $field );
329 $this->field_display_error( 'secondary', $field );
330 echo '</div>';
331
332 echo '</div>';
333 }
334 }
335
336 /**
337 * Edit form field display on the entry back-end.
338 *
339 * @since 1.7.0
340 *
341 * @param array $entry_field Entry field data.
342 * @param array $field Field data.
343 * @param array $form_data Form data and settings.
344 */
345 public function edit_form_field_display( $entry_field, $field, $form_data ) {
346 $value = isset( $entry_field['value'] ) ? $entry_field['value'] : '';
347
348 // Unset confirmation.
349 unset( $field['confirmation'] );
350
351 if ( '' !== $value ) {
352 $field['properties'] = $this->get_single_field_property_value( $value, 'primary', $field['properties'], $field );
353 }
354
355 $this->field_display( $field, null, $form_data );
356 }
357
358 /**
359 * Validates field on form submit.
360 *
361 * @param int $field_id Field ID.
362 * @param array $field_submit Submitted data.
363 * @param array $form_data Form data.
364 */
365 public function validate( $field_id, $field_submit, $form_data ) {
366 $form_id = (int) $form_data['id'];
367 $entry = $form_data['entry'];
368 $visible = apply_filters( 'everest_forms_visible_fields', true, $form_data['form_fields'][ $field_id ], $entry, $form_data );
369 $field_type = isset( $form_data['form_fields'][ $field_id ]['type'] ) ? $form_data['form_fields'][ $field_id ]['type'] : '';
370 $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' );
371 if ( false === $visible ) {
372 return;
373 }
374
375 // Required check.
376 if ( ! empty( $form_data['form_fields'][ $field_id ]['required'] ) ) {
377 $required = $required_message;
378
379 // Standard configuration, confirmation disabled.
380 if ( empty( $form_data['form_fields'][ $field_id ]['confirmation'] ) ) {
381 if ( empty( $field_submit ) && '0' !== $field_submit ) {
382 evf()->task->errors[ $form_id ][ $field_id ] = $required;
383 update_option( 'evf_validation_error', 'yes' );
384 }
385 } else {
386 if ( empty( $field_submit['primary'] ) && '0' !== $field_submit ) {
387 evf()->task->errors[ $form_id ][ $field_id ]['primary'] = $required;
388 update_option( 'evf_validation_error', 'yes' );
389 }
390
391 if ( empty( $field_submit['secondary'] ) && '0' !== $field_submit ) {
392 evf()->task->errors[ $form_id ][ $field_id ]['secondary'] = $required;
393 update_option( 'evf_validation_error', 'yes' );
394 }
395 }
396 }
397
398 // If confirmation disabled, treat this way for primary email.
399 if ( ! is_array( $field_submit ) && ! empty( $field_submit ) ) {
400 $field_submit = array(
401 'primary' => $field_submit,
402 );
403 }
404
405 // Standard checks for valid email address and confirmation email match.
406 if ( ! empty( $field_submit['primary'] ) && ! is_email( $field_submit['primary'] ) ) {
407 $invalid_email = esc_html__( 'Please enter a valid email address.', 'everest-forms' );
408 if ( empty( $form_data['form_fields'][ $field_id ]['confirmation'] ) ) {
409 evf()->task->errors[ $form_id ][ $field_id ] = $invalid_email;
410 } else {
411 evf()->task->errors[ $form_id ][ $field_id ]['primary'] = $invalid_email;
412 }
413 update_option( 'evf_validation_error', 'yes' );
414 } elseif ( isset( $field_submit['primary'], $field_submit['secondary'] ) && $field_submit['secondary'] !== $field_submit['primary'] ) {
415 evf()->task->errors[ $form_id ][ $field_id ]['secondary'] = esc_html__( 'Confirmation Email do not match.', 'everest-forms' );
416 update_option( 'evf_validation_error', 'yes' );
417 }
418
419 do_action( 'everest_forms_email_validation', $field_id, $field_submit, $form_data );
420 }
421
422 /**
423 * Formats and sanitizes field.
424 *
425 * @param int $field_id Field ID.
426 * @param array $field_submit Submitted field value.
427 * @param array $form_data Form data and settings.
428 * @param string $meta_key Field meta key.
429 */
430 public function format( $field_id, $field_submit, $form_data, $meta_key ) {
431 if ( is_array( $field_submit ) ) {
432 $value = ! empty( $field_submit['primary'] ) ? $field_submit['primary'] : '';
433 } else {
434 $value = ! empty( $field_submit ) ? $field_submit : '';
435 }
436
437 $name = ! empty( $form_data['form_fields'][ $field_id ]['label'] ) ? $form_data['form_fields'][ $field_id ]['label'] : '';
438
439 // Set final field details.
440 evf()->task->form_fields[ $field_id ] = array(
441 'name' => make_clickable( $name ),
442 'value' => sanitize_text_field( $value ),
443 'id' => $field_id,
444 'type' => $this->type,
445 'meta_key' => $meta_key,
446 );
447 }
448 }
449