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