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-text.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-text.php
359 lines
1 <?php
2 /**
3 * Text field.
4 *
5 * @package EverestForms\Fields
6 * @since 1.0.0
7 */
8
9 defined( 'ABSPATH' ) || exit;
10
11 /**
12 * EVF_Field_Text class.
13 */
14 class EVF_Field_Text extends EVF_Form_Fields {
15
16 /**
17 * Constructor.
18 */
19 public function __construct() {
20 $this->name = esc_html__( 'Single Line Text', 'everest-forms' );
21 $this->type = 'text';
22 $this->icon = 'evf-icon evf-icon-text';
23 $this->order = 30;
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 ),
35 ),
36 'advanced-options' => array(
37 'field_options' => array(
38 'placeholder',
39 'label_hide',
40 'limit_length',
41 'min_length',
42 'default_value',
43 'css',
44 'input_mask',
45 'regex_validation',
46 'regex_value',
47 'regex_message',
48 ),
49 ),
50 );
51
52 parent::__construct();
53 }
54
55 /**
56 * Hook in tabs.
57 */
58 public function init_hooks() {
59 add_action( 'everest_forms_shortcode_scripts', array( $this, 'load_assets' ) );
60 add_filter( 'everest_forms_field_properties_' . $this->type, array( $this, 'field_properties' ), 5, 3 );
61 }
62
63 /**
64 * Limit length field option.
65 *
66 * @param array $field Field settings.
67 */
68 public function limit_length( $field ) {
69 // Limit length.
70 $args = array(
71 'slug' => 'limit_enabled',
72 'content' => $this->field_element(
73 'checkbox',
74 $field,
75 array(
76 'slug' => 'limit_enabled',
77 'value' => isset( $field['limit_enabled'] ),
78 'desc' => esc_html__( 'Limit Length', 'everest-forms' ),
79 'tooltip' => esc_html__( 'Check this option to specify maximum text length by characters or word count.', 'everest-forms' ),
80 ),
81 false
82 ),
83 );
84 $this->field_element( 'row', $field, $args );
85
86 // Limit controls.
87 $count = $this->field_element(
88 'text',
89 $field,
90 array(
91 'type' => 'number',
92 'class' => 'small-text',
93 'slug' => 'limit_count',
94 'attrs' => array(
95 'min' => 1,
96 'step' => 1,
97 'pattern' => '[0-9]',
98 ),
99 'value' => ! empty( $field['limit_count'] ) ? absint( $field['limit_count'] ) : 1,
100 ),
101 false
102 );
103
104 $mode = $this->field_element(
105 'select',
106 $field,
107 array(
108 'slug' => 'limit_mode',
109 'class' => 'limit-select',
110 'value' => ! empty( $field['limit_mode'] ) ? esc_attr( $field['limit_mode'] ) : 'characters',
111 'options' => array(
112 'characters' => esc_html__( 'Characters', 'everest-forms' ),
113 'words' => esc_html__( 'Words Count', 'everest-forms' ),
114 ),
115 ),
116 false
117 );
118 $args = array(
119 'slug' => 'limit_controls',
120 'class' => ! isset( $field['limit_enabled'] ) ? 'everest-forms-hidden' : '',
121 'content' => $count . $mode,
122 );
123 $this->field_element( 'row', $field, $args );
124 }
125
126 /**
127 * Minimum Length length field option.
128 *
129 * @param array $field Field settings.
130 */
131 public function min_length( $field ) {
132 // Minimum length.
133 $args = array(
134 'slug' => 'min_length_enabled',
135 'content' => $this->field_element(
136 'checkbox',
137 $field,
138 array(
139 'slug' => 'min_length_enabled',
140 'value' => isset( $field['min_length_enabled'] ),
141 'desc' => esc_html__( 'Minimum Length', 'everest-forms' ),
142 'tooltip' => esc_html__( 'Check this option to specify minimum text length by characters or word count.', 'everest-forms' ),
143 ),
144 false
145 ),
146 );
147 $this->field_element( 'row', $field, $args );
148
149 // Minimum length controls.
150 $count = $this->field_element(
151 'text',
152 $field,
153 array(
154 'type' => 'number',
155 'class' => 'small-text',
156 'slug' => 'min_length_count',
157 'attrs' => array(
158 'min' => 1,
159 'step' => 1,
160 'pattern' => '[0-9]',
161 ),
162 'value' => ! empty( $field['min_length_count'] ) ? absint( $field['min_length_count'] ) : 1,
163 ),
164 false
165 );
166
167 $mode = $this->field_element(
168 'select',
169 $field,
170 array(
171 'slug' => 'min_length_mode',
172 'class' => 'min-length-select',
173 'value' => ! empty( $field['min_length_mode'] ) ? esc_attr( $field['min_length_mode'] ) : 'characters',
174 'options' => array(
175 'characters' => esc_html__( 'Characters', 'everest-forms' ),
176 'words' => esc_html__( 'Words Count', 'everest-forms' ),
177 ),
178 ),
179 false
180 );
181 $args = array(
182 'slug' => 'min_length_controls',
183 'class' => ! isset( $field['min_length_enabled'] ) ? 'everest-forms-hidden' : '',
184 'content' => $count . $mode,
185 );
186 $this->field_element( 'row', $field, $args );
187 }
188
189 /**
190 * Input mask field option.
191 *
192 * @param array $field Field settings.
193 */
194 public function input_mask( $field ) {
195 // Input Mask.
196 $lbl = $this->field_element(
197 'label',
198 $field,
199 array(
200 'slug' => 'input_mask',
201 'value' => esc_html__( 'Input Mask', 'everest-forms' ),
202 'tooltip' => esc_html__( 'Enter your custom input mask.', 'everest-forms' ),
203 'after_tooltip' => '<a href="https://docs.everestforms.net/docs/how-to-use-custom-input-mask/" class="after-label-description" target="_blank" rel="noopener noreferrer">' . esc_html__( 'See Examples & Docs', 'everest-forms' ) . '</a>',
204 ),
205 false
206 );
207 $fld = $this->field_element(
208 'text',
209 $field,
210 array(
211 'slug' => 'input_mask',
212 'value' => ! empty( $field['input_mask'] ) ? esc_attr( $field['input_mask'] ) : '',
213 ),
214 false
215 );
216 $this->field_element(
217 'row',
218 $field,
219 array(
220 'slug' => 'input_mask',
221 'content' => $lbl . $fld,
222 )
223 );
224 }
225
226 /**
227 * Enqueue shortcode scripts.
228 *
229 * @param array $atts Shortcode Attributes.
230 */
231 public function load_assets( $atts ) {
232 $form_id = isset( $atts['id'] ) ? wp_unslash( $atts['id'] ) : ''; // WPCS: CSRF ok, input var ok, sanitization ok.
233 $form_obj = evf()->form->get( $form_id );
234 $form_data = ! empty( $form_obj->post_content ) ? evf_decode( $form_obj->post_content ) : '';
235
236 // Leave only fields with limit.
237 if ( ! empty( $form_data['form_fields'] ) ) {
238 $form_fields = array_filter( $form_data['form_fields'], array( $this, 'field_is_limit' ) );
239
240 if ( count( $form_fields ) ) {
241 wp_enqueue_script( 'everest-forms-text-limit' );
242 }
243 }
244 }
245
246 /**
247 * Define additional field properties.
248 *
249 * @since 1.0.0
250 *
251 * @param array $properties Field properties.
252 * @param array $field Field settings.
253 * @param array $form_data Form data and settings.
254 *
255 * @return array of additional field properties.
256 */
257 public function field_properties( $properties, $field, $form_data ) {
258 // Input primary: Detect custom input mask.
259 if ( ! empty( $field['input_mask'] ) ) {
260 // Add class that will trigger custom mask.
261 $properties['inputs']['primary']['class'][] = 'evf-masked-input';
262
263 // Register string for translation.
264 $field['input_mask'] = evf_string_translation( $form_data['id'], $field['id'], $field['input_mask'], '-input-mask' );
265
266 if ( false !== strpos( $field['input_mask'], 'alias:' ) ) {
267 $mask = str_replace( 'alias:', '', $field['input_mask'] );
268 $properties['inputs']['primary']['data']['inputmask-alias'] = $mask;
269 } elseif ( false !== strpos( $field['input_mask'], 'regex:' ) ) {
270 $mask = str_replace( 'regex:', '', $field['input_mask'] );
271 $properties['inputs']['primary']['data']['inputmask-regex'] = $mask;
272 } elseif ( false !== strpos( $field['input_mask'], 'date:' ) ) {
273 $mask = str_replace( 'date:', '', $field['input_mask'] );
274 $properties['inputs']['primary']['data']['inputmask-alias'] = 'datetime';
275 $properties['inputs']['primary']['data']['inputmask-inputformat'] = $mask;
276 } else {
277 $properties['inputs']['primary']['data']['inputmask-mask'] = $field['input_mask'];
278 }
279 }
280
281 return $properties;
282 }
283
284 /**
285 * Field preview inside the builder.
286 *
287 * @param array $field Field data and settings.
288 */
289 public function field_preview( $field ) {
290 // Define data.
291 $placeholder = ! empty( $field['placeholder'] ) ? esc_attr( $field['placeholder'] ) : '';
292
293 // Label.
294 $this->field_preview_option( 'label', $field );
295
296 // Primary input.
297 echo '<input type="text" placeholder="' . esc_attr( $placeholder ) . '" class="widefat" disabled>';
298
299 // Description.
300 $this->field_preview_option( 'description', $field );
301 }
302
303 /**
304 * Field display on the form front-end.
305 *
306 * @since 1.0.0
307 *
308 * @param array $field Field Data.
309 * @param array $field_atts Field attributes.
310 * @param array $form_data All Form Data.
311 */
312 public function field_display( $field, $field_atts, $form_data ) {
313 // Define data.
314 $primary = apply_filters( 'everest_forms_default_values', $field['properties']['inputs']['primary'] );
315
316 // Limit length.
317 if ( isset( $field['limit_enabled'] ) ) {
318 $limit_count = isset( $field['limit_count'] ) ? absint( $field['limit_count'] ) : 0;
319 $limit_mode = isset( $field['limit_mode'] ) ? sanitize_key( $field['limit_mode'] ) : 'characters';
320
321 $primary['data']['form-id'] = $form_data['id'];
322 $primary['data']['field-id'] = $field['id'];
323
324 if ( 'characters' === $limit_mode ) {
325 $primary['class'][] = 'everest-forms-limit-characters-enabled';
326 $primary['attr']['maxlength'] = $limit_count;
327 $primary['data']['text-limit'] = $limit_count;
328 } else {
329 $primary['class'][] = 'everest-forms-limit-words-enabled';
330 $primary['data']['text-limit'] = $limit_count;
331 }
332 }
333
334 // Minimum length.
335 if ( isset( $field['min_length_enabled'] ) ) {
336 $min_length_count = isset( $field['min_length_count'] ) ? absint( $field['min_length_count'] ) : 0;
337 $min_length_mode = isset( $field['min_length_mode'] ) ? sanitize_key( $field['min_length_mode'] ) : 'characters';
338
339 $primary['data']['form-id'] = $form_data['id'];
340 $primary['data']['field-id'] = $field['id'];
341
342 if ( 'characters' === $min_length_mode ) {
343 $primary['class'][] = 'everest-forms-min-characters-length-enabled';
344 $primary['attr']['minlength'] = $min_length_count;
345 $primary['data']['text-min-length'] = $min_length_count;
346 } else {
347 $primary['class'][] = 'everest-forms-min-words-length-enabled';
348 $primary['data']['text-min-length'] = $min_length_count;
349 }
350 }
351
352 printf(
353 '<input type="text" %s %s>',
354 evf_html_attributes( $primary['id'], $primary['class'], $primary['data'], $primary['attr'] ),
355 esc_attr( $primary['required'] )
356 );
357 }
358 }
359