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-name.php

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

242 lines 9.0 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_Name extends WeForms_Field_Contract {
7
8 function __construct() {
9 $this->name = __( 'Name', 'weforms' );
10 $this->input_type = 'name_field';
11 $this->icon = 'user';
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
25 // let's not show the name field if user choose to auto populate for logged users
26 if ( isset( $field_settings['auto_populate'] ) && $field_settings['auto_populate'] == 'yes' && is_user_logged_in() ) {
27 return;
28 }
29
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 <div class="wpuf-name-field-wrap format-<?php echo $field_settings['format']; ?>">
36 <div class="wpuf-name-field-first-name">
37 <input
38 name="<?php echo $field_settings['name'] ?>[first]"
39 type="text"
40 placeholder="<?php echo esc_attr( $field_settings['first_name']['placeholder'] ); ?>"
41 value="<?php echo esc_attr( $field_settings['first_name']['default'] ); ?>"
42 size="40"
43 data-required="<?php echo $field_settings['required'] ?>"
44 data-type="text"
45 class="textfield wpuf_<?php echo $field_settings['name']; ?>_<?php echo $form_id; ?>"
46 autocomplete="given-name"
47 >
48
49 <?php if ( ! $field_settings['hide_subs'] ) : ?>
50 <label class="wpuf-form-sub-label"><?php _e( 'First', 'weforms' ); ?></label>
51 <?php endif; ?>
52 </div>
53
54 <?php if ( $field_settings['format'] != 'first-last' ) : ?>
55 <div class="wpuf-name-field-middle-name">
56 <input
57 name="<?php echo $field_settings['name'] ?>[middle]"
58 type="text" class="textfield"
59 placeholder="<?php echo esc_attr( $field_settings['middle_name']['placeholder'] ); ?>"
60 value="<?php echo esc_attr( $field_settings['middle_name']['default'] ); ?>"
61 size="40"
62 autocomplete="additional-name"
63 >
64
65 <?php if ( ! $field_settings['hide_subs'] ) : ?>
66 <label class="wpuf-form-sub-label"><?php _e( 'Middle', 'weforms' ); ?></label>
67 <?php endif; ?>
68 </div>
69 <?php else: ?>
70 <input type="hidden" name="<?php echo $field_settings['name'] ?>[middle]" value="">
71 <?php endif; ?>
72
73 <div class="wpuf-name-field-last-name">
74 <input
75 name="<?php echo $field_settings['name'] ?>[last]"
76 type="text" class="textfield"
77 placeholder="<?php echo esc_attr( $field_settings['last_name']['placeholder'] ); ?>"
78 value="<?php echo esc_attr( $field_settings['last_name']['default'] ); ?>"
79 size="40"
80 autocomplete="family-name"
81 >
82 <?php if ( ! $field_settings['hide_subs'] ) : ?>
83 <label class="wpuf-form-sub-label"><?php _e( 'Last', 'weforms' ); ?></label>
84 <?php endif; ?>
85 </div>
86 </div>
87 <?php $this->help_text( $field_settings ); ?>
88 </div>
89 </li>
90 <?php
91 }
92
93 /**
94 * Get field options setting
95 *
96 * @return array
97 */
98 public function get_options_settings() {
99 $default_options = $this->get_default_option_settings( true, array( 'width' ) );
100
101 $name_settings = array(
102 array(
103 'name' => 'format',
104 'title' => __( 'Format', 'weforms' ),
105 'type' => 'radio',
106 'options' => array(
107 'first-last' => __( 'First and Last name', 'weforms' ),
108 'first-middle-last' => __( 'First, Middle and Last name', 'weforms' )
109 ),
110 'selected' => 'first-last',
111 'section' => 'advanced',
112 'priority' => 20,
113 'help_text' => __( 'Select format to use for the name field', 'weforms' ),
114 ),
115 array(
116 'name' => 'auto_populate',
117 'title' => 'Auto-populate name for logged users',
118 'type' => 'checkbox',
119 'is_single_opt' => true,
120 'options' => array(
121 'yes' => __( 'Auto-populate Name', 'weforms' )
122 ),
123 'default' => '',
124 'section' => 'advanced',
125 'priority' => 23,
126 'help_text' => __( 'If a user is logged into the site, this name field will be auto-populated with his first-last/display name. And form\'s name field will be hidden.', 'weforms' ),
127 ),
128 array(
129 'name' => 'sub-labels',
130 'title' => __( 'Label', 'weforms' ),
131 'type' => 'name',
132 'section' => 'advanced',
133 'priority' => 21,
134 'help_text' => __( 'Select format to use for the name field', 'weforms' ),
135 ),
136 array(
137 'name' => 'hide_subs',
138 'title' => '',
139 'type' => 'checkbox',
140 'is_single_opt' => true,
141 'options' => array(
142 'true' => __( 'Hide Sub Labels', 'weforms' )
143 ),
144 'section' => 'advanced',
145 'priority' => 23,
146 'help_text' => '',
147 ),
148 array(
149 'name' => 'inline',
150 'title' => __( 'Show in inline list', 'weforms' ),
151 'type' => 'radio',
152 'options' => array(
153 'yes' => __( 'Yes', 'weforms' ),
154 'no' => __( 'No', 'weforms' ),
155 ),
156 'default' => 'no',
157 'inline' => true,
158 'section' => 'advanced',
159 'priority' => 23,
160 'help_text' => __( 'Show this option in an inline list', 'weforms' ),
161 )
162 );
163
164 return array_merge( $default_options, $name_settings );
165 }
166
167 /**
168 * Get the field props
169 *
170 * @return array
171 */
172 public function get_field_props() {
173 $defaults = $this->default_attributes();
174 $props = array(
175 'format' => 'first-last',
176 'first_name' => array(
177 'placeholder' => '',
178 'default' => '',
179 'sub' => __( 'First', 'weforms' )
180 ),
181 'middle_name' => array(
182 'placeholder' => '',
183 'default' => '',
184 'sub' => __( 'Middle', 'weforms' )
185 ),
186 'last_name' => array(
187 'placeholder' => '',
188 'default' => '',
189 'sub' => __( 'Last', 'weforms' )
190 ),
191 'inline' => 'yes',
192 'hide_subs' => false,
193 );
194
195 return array_merge( $defaults, $props );
196 }
197
198 /**
199 * Prepare entry default, can be replaced through field classes
200 *
201 * @param $field
202 *
203 * @return mixed
204 */
205 public function prepare_entry( $field ) {
206
207 if ( isset( $field['auto_populate'] ) && $field['auto_populate'] == 'yes' && is_user_logged_in() ) {
208
209 $user = wp_get_current_user();
210
211 if ( ! empty( $user->ID ) ) {
212
213 if ( $user->first_name || $user->last_name ) {
214
215 $name = array();
216 $name[] = $user->first_name;
217 $name[] = $user->last_name;
218
219 return implode( WeForms::$field_separator, $name );
220 } else {
221
222 return $user->display_name;
223 }
224
225 }
226 }
227
228 $value = !empty( $_POST[$field['name']] ) ? $_POST[$field['name']] : '';
229
230 if ( is_array( $value ) ) {
231
232 $entry_value = implode( WeForms::$field_separator, $_POST[$field['name']] );
233
234 } else {
235 $entry_value = trim( $value );
236 }
237
238 return $entry_value;
239 }
240
241 }
242