PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.2.8
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.2.8
1.6.7 1.6.8 1.6.9 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.3 1.6.4 1.6.5 1.6.6 All 74 releases
weforms / includes / fields / class-field-email.php

class-field-email.php in weForms – Easy Drag & Drop Contact Form Builder For WordPress 1.2.8, at includes/fields/class-field-email.php

128 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Text Field Class
5 */
6 class WeForms_Form_Field_Email extends WeForms_Form_Field_Text {
7
8 function __construct() {
9 $this->name = __( 'Email Address', 'weforms' );
10 $this->input_type = 'email_address';
11 $this->icon = 'envelope-o';
12 }
13
14 /**
15 * Render the text field
16 *
17 * @param array $field_settings
18 * @param integer $form_id
19 *
20 * @return void
21 */
22 public function render( $field_settings, $form_id ) {
23
24 // let's not show the email field if user choose to auto populate for logged users
25 if ( isset( $field_settings['auto_populate'] ) && $field_settings['auto_populate'] == 'yes' && is_user_logged_in() ) {
26 return;
27 }
28
29 $value = $field_settings['default'];
30 ?>
31 <li <?php $this->print_list_attributes( $field_settings ); ?>>
32 <?php $this->print_label( $field_settings, $form_id ); ?>
33
34 <div class="wpuf-fields">
35 <input
36 id="<?php echo $field_settings['name'] . '_' . $form_id; ?>"
37 type="email"
38 class="email <?php echo ' wpuf_'.$field_settings['name'].'_'.$form_id; ?>"
39 data-duplicate="<?php echo isset( $field_settings['duplicate'] ) ? $field_settings['duplicate'] : 'no'; ?>"
40 data-required="<?php echo $field_settings['required'] ?>"
41 data-type="email"
42 name="<?php echo esc_attr( $field_settings['name'] ); ?>"
43 placeholder="<?php echo esc_attr( $field_settings['placeholder'] ); ?>"
44 value="<?php echo esc_attr( $value ) ?>"
45 size="<?php echo esc_attr( $field_settings['size'] ) ?>"
46 autocomplete="email"
47 />
48 <?php $this->help_text( $field_settings ); ?>
49 </div>
50 </li>
51 <?php
52 }
53
54 /**
55 * Get field options setting
56 *
57 * @return array
58 */
59 public function get_options_settings() {
60 $default_options = $this->get_default_option_settings();
61 $default_text_options = $this->get_default_text_option_settings();
62 $check_duplicate = array(
63 array(
64 'name' => 'duplicate',
65 'title' => 'No Duplicates',
66 'type' => 'checkbox',
67 'is_single_opt' => true,
68 'options' => array(
69 'no' => __( 'Unique Values Only', 'weforms' )
70 ),
71 'default' => '',
72 'section' => 'advanced',
73 'priority' => 23,
74 'help_text' => __( 'Select this option to limit user input to unique values only. This will require that a value entered in a field does not currently exist in the entry database for that field.', 'weforms' ),
75 ),
76 array(
77 'name' => 'auto_populate',
78 'title' => 'Auto-populate email for logged users',
79 'type' => 'checkbox',
80 'is_single_opt' => true,
81 'options' => array(
82 'yes' => __( 'Auto-populate Email', 'weforms' )
83 ),
84 'default' => '',
85 'section' => 'advanced',
86 'priority' => 23,
87 'help_text' => __( 'If a user is logged into the site, this email field will be auto-populated with his email. And form\'s email field will be hidden.', 'weforms' ),
88 ),
89 );
90
91 return array_merge( $default_options, $default_text_options, $check_duplicate );
92 }
93
94 /**
95 * Prepare entry default, can be replaced through field classes
96 *
97 * @param $field
98 *
99 * @return mixed
100 */
101 public function prepare_entry( $field ) {
102
103 if ( isset( $field['auto_populate'] ) && $field['auto_populate'] == 'yes' && is_user_logged_in() ) {
104
105 $user = wp_get_current_user();
106
107 if ( ! empty( $user->user_email ) ) {
108 return $user->user_email;
109 }
110 }
111
112 $value = !empty( $_POST[$field['name']] ) ? $_POST[$field['name']] : '';
113
114 return sanitize_text_field( trim( $value ) );
115 }
116
117 /**
118 * Get the field props
119 *
120 * @return array
121 */
122 public function get_field_props() {
123 $defaults = $this->default_attributes();
124 $defaults['duplicate'] = '';
125 return $defaults;
126 }
127 }
128