PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.6.4
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.6.4
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.6.4, at includes/fields/class-field-email.php

136 lines 5.1 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 public 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 int $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 <li <?php $this->print_list_attributes( $field_settings ); ?>>
31 <?php $this->print_label( $field_settings, $form_id ); ?>
32
33 <div class="wpuf-fields">
34 <input
35 id="<?php echo esc_attr( $field_settings['name'] ) . '_' . esc_attr( $form_id ); ?>"
36 type="email"
37 class="email <?php echo ' wpuf_'. esc_attr( $field_settings['name'] ).'_'. esc_attr( $form_id ); ?>"
38 data-duplicate="<?php echo isset( $field_settings['duplicate'] ) ? esc_attr( $field_settings['duplicate'] ) : 'no'; ?>"
39 data-required="<?php echo esc_attr( $field_settings['required'] ) ?>"
40 data-type="email"
41 name="<?php echo esc_attr( $field_settings['name'] ); ?>"
42 placeholder="<?php echo esc_attr( $field_settings['placeholder'] ); ?>"
43 value="<?php echo esc_attr( $value ); ?>"
44 size="<?php echo esc_attr( $field_settings['size'] ); ?>"
45 autocomplete="email"
46 />
47 <?php $this->help_text( $field_settings ); ?>
48 </div>
49 </li>
50 <?php
51 }
52
53 /**
54 * Get field options setting
55 *
56 * @return array
57 */
58 public function get_options_settings() {
59 $default_options = $this->get_default_option_settings();
60 $default_text_options = $this->get_default_text_option_settings();
61 $check_duplicate = [
62 [
63 'name' => 'duplicate',
64 'title' => 'No Duplicates',
65 'type' => 'checkbox',
66 'is_single_opt' => true,
67 'options' => [
68 'no' => __( 'Unique Values Only', 'weforms' ),
69 ],
70 'default' => '',
71 'section' => 'advanced',
72 'priority' => 23,
73 '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' ),
74 ],
75 [
76 'name' => 'auto_populate',
77 'title' => 'Auto-populate email for logged users',
78 'type' => 'checkbox',
79 'is_single_opt' => true,
80 'options' => [
81 'yes' => __( 'Auto-populate Email', 'weforms' ),
82 ],
83 'default' => '',
84 'section' => 'advanced',
85 'priority' => 23,
86 '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' ),
87 ],
88 ];
89
90 return array_merge( $default_options, $default_text_options, $check_duplicate );
91 }
92
93 /**
94 * Prepare entry default, can be replaced through field classes
95 *
96 * @param $field
97 *
98 * @return mixed
99 */
100 public function prepare_entry( $field, $args = [] ) {
101 if( empty( $_POST['_wpnonce'])) {
102 wp_send_json_error( __( 'Unauthorized operation', 'weforms' ) );
103 }
104
105 if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ), 'wpuf_form_add' ) ) {
106 wp_send_json_error( __( 'Unauthorized operation', 'weforms' ) );
107 }
108
109 $args = ! empty( $args ) ? $args : weforms_clean( $_POST );
110
111 if ( isset( $field['auto_populate'] ) && $field['auto_populate'] == 'yes' && is_user_logged_in() ) {
112 $user = wp_get_current_user();
113
114 if ( !empty( $user->user_email ) ) {
115 return $user->user_email;
116 }
117 }
118
119 $value = !empty( $args[ $field[ 'name' ] ] ) ? $args[ $field[ 'name' ] ] : '';
120
121 return sanitize_text_field( trim( $value ) );
122 }
123
124 /**
125 * Get the field props
126 *
127 * @return array
128 */
129 public function get_field_props() {
130 $defaults = $this->default_attributes();
131 $defaults['duplicate'] = '';
132
133 return $defaults;
134 }
135 }
136