PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 1.6.3
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v1.6.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-date-time.php
everest-forms / includes / fields Last commit date
class-evf-field-address.php 7 years ago class-evf-field-checkbox.php 6 years ago class-evf-field-country.php 7 years ago class-evf-field-credit-card.php 7 years ago class-evf-field-date-time.php 6 years ago class-evf-field-email.php 6 years ago class-evf-field-file-upload.php 6 years ago class-evf-field-first-name.php 6 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 6 years ago class-evf-field-likert.php 7 years ago class-evf-field-number.php 6 years ago class-evf-field-password.php 7 years ago class-evf-field-payment-checkbox.php 7 years ago class-evf-field-payment-quantity.php 6 years ago class-evf-field-payment-radio.php 7 years ago class-evf-field-payment-single.php 7 years ago class-evf-field-payment-total.php 6 years ago class-evf-field-phone.php 7 years ago class-evf-field-radio.php 6 years ago class-evf-field-rating.php 7 years ago class-evf-field-scale-rating.php 7 years ago class-evf-field-select.php 6 years ago class-evf-field-signature.php 7 years ago class-evf-field-text.php 6 years ago class-evf-field-textarea.php 6 years ago class-evf-field-title.php 6 years ago class-evf-field-url.php 6 years ago
class-evf-field-date-time.php
503 lines
1 <?php
2 /**
3 * Date and Time field.
4 *
5 * @package EverestForms\Fields
6 * @since 1.0.0
7 */
8
9 defined( 'ABSPATH' ) || exit;
10
11 /**
12 * EVF_Field_Date_Time class.
13 */
14 class EVF_Field_Date_Time extends EVF_Form_Fields {
15
16 /**
17 * Constructor.
18 */
19 public function __construct() {
20 $this->name = esc_html__( 'Date / Time', 'everest-forms' );
21 $this->type = 'date-time';
22 $this->icon = 'evf-icon evf-icon-calendar';
23 $this->order = 20;
24 $this->group = 'advanced';
25 $this->settings = array(
26 'basic-options' => array(
27 'field_options' => array(
28 'label',
29 'meta',
30 'choose_format',
31 'description',
32 'required',
33 'required_field_message',
34 ),
35 ),
36 'advanced-options' => array(
37 'field_options' => array(
38 'placeholder',
39 'datetime_options',
40 'label_hide',
41 'css',
42 ),
43 ),
44 );
45
46 parent::__construct();
47 }
48
49 /**
50 * Hook in tabs.
51 */
52 public function init_hooks() {
53 add_action( 'everest_forms_shortcode_scripts', array( $this, 'load_assets' ) );
54 add_filter( 'everest_forms_field_properties_' . $this->type, array( $this, 'field_properties' ), 5, 3 );
55 }
56
57 /**
58 * Date field format option.
59 *
60 * @since 1.4.9
61 * @param array $field Field Data.
62 */
63 public function choose_format( $field ) {
64 $format = ! empty( $field['datetime_format'] ) ? esc_attr( $field['datetime_format'] ) : 'date';
65 $format_label = $this->field_element(
66 'label',
67 $field,
68 array(
69 'slug' => 'datetime_format',
70 'value' => esc_html__( 'Format', 'everest-forms' ),
71 'tooltip' => esc_html__( 'Select a format for the date field.', 'everest-forms' ),
72 ),
73 false
74 );
75 $format_select = $this->field_element(
76 'select',
77 $field,
78 array(
79 'slug' => 'datetime_format',
80 'value' => $format,
81 'options' => array(
82 'date' => esc_html__( 'Date', 'everest-forms' ),
83 'time' => esc_html__( 'Time', 'everest-forms' ),
84 'date-time' => esc_html__( 'Both', 'everest-forms' ),
85 ),
86 ),
87 false
88 );
89 $args = array(
90 'slug' => 'datetime_format',
91 'content' => $format_label . $format_select,
92 );
93 $this->field_element( 'row', $field, $args );
94 }
95
96 /**
97 * Date and time advanced field options.
98 *
99 * @since 1.4.9
100 * @param array $field Field Data.
101 */
102 public function datetime_options( $field ) {
103 $format = ! empty( $field['datetime_format'] ) ? esc_attr( $field['datetime_format'] ) : 'date';
104 $class_name = isset( $field['enable_min_max'] ) && '1' === $field['enable_min_max'] ? '' : 'everest-forms-hidden';
105 $field['date_mode'] = isset( $field['date_mode'] ) ? $field['date_mode'] : 'single';
106 $field['date_mode'] = isset( $field['date_range'] ) && '1' === $field['date_range'] ? 'range' : $field['date_mode'];
107
108 $this->field_element(
109 'label',
110 $field,
111 array(
112 'slug' => 'datetime_advanced',
113 'value' => esc_html__( 'Date & Time Format', 'everest-forms' ),
114 'tooltip' => esc_html__( 'Advanced date and time formatting options.', 'everest-forms' ),
115 ),
116 true
117 );
118
119 echo '<div class="format-selected-' . esc_attr( $format ) . ' format-selected">';
120 echo '<div class="everest-forms-border-container everest-forms-date">';
121 echo '<h4 class="everest-forms-border-container-title">' . esc_html__( 'Date', 'everest-forms' ) . '</h4>'; // phpcs:ignore WordPress.Security.NonceVerification
122
123 $date_format_label = $this->field_element(
124 'label',
125 $field,
126 array(
127 'slug' => 'date_format',
128 'value' => esc_html__( 'Date Format', 'everest-forms' ),
129 'tooltip' => esc_html__( 'Choose a desire date format to display.', 'everest-forms' ),
130 ),
131 false
132 );
133
134 $date_format_select = $this->field_element(
135 'select',
136 $field,
137 array(
138 'slug' => 'date_format',
139 'value' => isset( $field['date_format'] ) ? $field['date_format'] : 'Y-m-d',
140 'options' => array(
141 'Y-m-d' => date( 'Y-m-d' ) . ' (Y-m-d)', // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
142 'F j, Y' => date( 'F j, Y' ) . ' (F j, Y)', // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
143 'm/d/Y' => date( 'm/d/Y' ) . ' (m/d/Y)', // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
144 'd/m/Y' => date( 'd/m/Y' ) . ' (d/m/Y)', // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
145 ),
146 ),
147 false
148 );
149
150 $current_date_mode = $this->field_element(
151 'radio',
152 $field,
153 array(
154 'slug' => 'date_mode',
155 'default' => isset( $field['date_mode'] ) ? $field['date_mode'] : 'single',
156 'desc' => esc_html__( 'Date Mode', 'everest-forms' ),
157 'tooltip' => esc_html__( 'Select your desire date mode.', 'everest-forms' ),
158 'options' => array(
159 'single' => 'Single',
160 'range' => 'Range',
161 'multiple' => 'Multiple',
162 ),
163 ),
164 false
165 );
166
167 $date_localization_label = $this->field_element(
168 'label',
169 $field,
170 array(
171 'slug' => 'date_localization',
172 'value' => esc_html__( 'Date Localization', 'everest-forms' ),
173 'tooltip' => esc_html__( 'Choose a desire date localization to display.', 'everest-forms' ),
174 ),
175 false
176 );
177
178 $date_localization_select = $this->field_element(
179 'select',
180 $field,
181 array(
182 'slug' => 'date_localization',
183 'value' => isset( $field['date_localization'] ) ? $field['date_localization'] : 'en',
184 'options' => array(
185 'en' => 'English',
186 'ar' => 'Arabic',
187 'at' => 'Austria',
188 'az' => 'Azerbaijan',
189 'be' => 'Belarusian',
190 'bg' => 'Bulgarian',
191 'bn' => 'Bangla',
192 'bs' => 'Bosnian',
193 'cat' => 'Catalan',
194 'cs' => 'Czech',
195 'cy' => 'Welsh',
196 'da' => 'Danish',
197 'de' => 'German',
198 'eo' => 'Esperanto',
199 'es' => 'Spanish',
200 'et' => 'Estonian',
201 'fa' => 'Persian',
202 'fi' => 'Finnish',
203 'fo' => 'Faroese',
204 'fr' => 'French',
205 'ga' => 'Irish',
206 'gr' => 'Greek',
207 'he' => 'Hebrew',
208 'hi' => 'Hindi',
209 'hr' => 'Croatian',
210 'hu' => 'Hungarian',
211 'id' => 'Indonesian',
212 'is' => 'Icelandic',
213 'it' => 'Italian',
214 'ja' => 'Japanese',
215 'ka' => 'Georgian',
216 'ko' => 'Korean',
217 'km' => 'Khmer',
218 'kz' => 'Kazakh',
219 'lt' => 'Lithuanian',
220 'lv' => 'Latvian',
221 'mk' => 'Macedonian',
222 'mn' => 'Mongolian',
223 'ms' => 'Malaysian',
224 'my' => 'Burmese',
225 'nl' => 'Dutch',
226 'no' => 'Norwegian',
227 'pa' => 'Punjabi',
228 'pl' => 'Polish',
229 'pt' => 'Portuguese',
230 'ro' => 'Romanian',
231 'ru' => 'Russian',
232 'si' => 'Sinhala',
233 'sk' => 'Slovak',
234 'sl' => 'Slovenian',
235 'sq' => 'Albanian',
236 'sr' => 'Serbian',
237 'sv' => 'Swedish',
238 'th' => 'Thai',
239 'tr' => 'Turkish',
240 'uk' => 'Ukrainian',
241 'vn' => 'Vietnamese',
242 'zh' => 'Mandarin',
243 'zh_tw' => 'MandarinTraditional',
244 ),
245 ),
246 false
247 );
248
249 $current_date_default = $this->field_element(
250 'checkbox',
251 $field,
252 array(
253 'slug' => 'date_default',
254 'value' => isset( $field['date_default'] ) ? $field['date_default'] : '',
255 'desc' => esc_html__( 'Default to current date.', 'everest-forms' ),
256 'tooltip' => esc_html__( 'Check this option to set current date as default.', 'everest-forms' ),
257 ),
258 false
259 );
260
261 $enable_min_max = $this->field_element(
262 'checkbox',
263 $field,
264 array(
265 'slug' => 'enable_min_max',
266 'value' => isset( $field['enable_min_max'] ) ? $field['enable_min_max'] : '',
267 'desc' => esc_html__( 'Enable Min Max date.', 'everest-forms' ),
268 'tooltip' => esc_html__( 'Check this option to set min max date.', 'everest-forms' ),
269 ),
270 false
271 );
272
273 $min_date_label = $this->field_element(
274 'label',
275 $field,
276 array(
277 'slug' => 'min_date',
278 'value' => esc_html__( 'Minimum Date', 'everest-forms' ),
279 'tooltip' => esc_html__( 'Select minium date.', 'everest-forms' ),
280 ),
281 false
282 );
283
284 $min_date = $this->field_element(
285 'text',
286 $field,
287 array(
288 'slug' => 'min_date',
289 'value' => isset( $field['min_date'] ) ? $field['min_date'] : '',
290 'class' => 'everest-forms-min-date',
291 ),
292 false
293 );
294
295 $max_date_label = $this->field_element(
296 'label',
297 $field,
298 array(
299 'slug' => 'max_date',
300 'value' => esc_html__( 'Maximum Date', 'everest-forms' ),
301 'tooltip' => esc_html__( 'Select maximum date.', 'everest-forms' ),
302 ),
303 false
304 );
305
306 $max_date = $this->field_element(
307 'text',
308 $field,
309 array(
310 'slug' => 'max_date',
311 'value' => isset( $field['max_date'] ) ? $field['max_date'] : '',
312 'class' => 'everest-forms-max-date',
313 ),
314 false
315 );
316
317 $args = array(
318 'slug' => 'date_format',
319 'content' => $date_format_label . $date_format_select . $date_localization_label . $date_localization_select . '<div class="everest-forms-checklist everest-forms-checklist-inline">' . $current_date_mode . '</div><div class="everest-forms-current-date-format">' . $current_date_default . '</div><div class="everest-forms-min-max-date-format">' . $enable_min_max . '</div><div class="everest-forms-min-max-date-option ' . $class_name . '">' . $min_date_label . $min_date . $max_date_label . $max_date . '</div>',
320 );
321 $this->field_element( 'row', $field, $args );
322
323 echo '</div>';
324
325 echo '<div class="everest-forms-border-container everest-forms-time">';
326 echo '<h4 class="everest-forms-border-container-title">' . esc_html__( 'Time', 'everest-forms' ) . '</h4>'; // phpcs:ignore WordPress.Security.NonceVerification
327
328 $time_format_label = $this->field_element(
329 'label',
330 $field,
331 array(
332 'slug' => 'time_interval',
333 'value' => esc_html__( 'Time interval and format', 'everest-forms' ),
334 'tooltip' => esc_html__( 'Choose time interval and format to display.', 'everest-forms' ),
335 ),
336 false
337 );
338
339 $time_interval_select = '<div class="input-group-col-2">';
340 $time_interval_select .= $this->field_element(
341 'select',
342 $field,
343 array(
344 'slug' => 'time_interval',
345 'value' => isset( $field['time_interval'] ) ? $field['time_interval'] : '',
346 'class' => 'time_interval',
347 'options' => array(
348 '15' => esc_html__( '15 minutes', 'everest-forms' ),
349 '30' => esc_html__( '30 minutes', 'everest-forms' ),
350 ),
351 ),
352 false
353 );
354 $time_format_select = $this->field_element(
355 'select',
356 $field,
357 array(
358 'slug' => 'time_format',
359 'value' => isset( $field['time_format'] ) ? $field['time_format'] : '',
360 'class' => 'time_format',
361 'options' => array(
362 'g:i A' => esc_html__( '12 H', 'everest-forms' ),
363 'H:i' => esc_html__( '24 H', 'everest-forms' ),
364 ),
365 ),
366 false
367 );
368 $time_format_select .= '</div>';
369
370 $args = array(
371 'slug' => 'time_interval_format',
372 'content' => $time_format_label . $time_interval_select . $time_format_select,
373 );
374 $this->field_element( 'row', $field, $args );
375
376 echo '</div>';
377 echo '</div>';
378 }
379
380 /**
381 * Define additional field properties.
382 *
383 * @param array $properties Field properties.
384 * @param array $field Field settings.
385 * @param array $form_data Form data and settings.
386 * @return array of additional field properties.
387 */
388 public function field_properties( $properties, $field, $form_data ) {
389 // Input primary: data-time-interval.
390 if ( ! empty( $field['time_interval'] ) ) {
391 $properties['inputs']['primary']['attr']['data-time-interval'] = esc_attr( $field['time_interval'] );
392 }
393
394 // Input primary: data-date-time.
395 if ( ! empty( $field['datetime_format'] ) ) {
396 $properties['inputs']['primary']['attr']['data-date-time'] = esc_attr( $field['datetime_format'] );
397
398 // Input primary: data-mode.
399 if ( 'time' !== $field['datetime_format'] ) {
400 if ( isset( $field['date_range'] ) && '1' === $field['date_range'] ) {
401 $properties['inputs']['primary']['attr']['data-mode'] = 'range';
402 } else {
403 $properties['inputs']['primary']['attr']['data-mode'] = isset( $field['date_mode'] ) ? $field['date_mode'] : 'single';
404 }
405 $properties['inputs']['primary']['attr']['data-locale'] = isset( $field['date_localization'] ) ? $field['date_localization'] : 'en';
406 $properties['inputs']['primary']['attr']['data-min-date'] = isset( $field['enable_min_max'], $field['min_date'] ) ? $field['min_date'] : '';
407 $properties['inputs']['primary']['attr']['data-max-date'] = isset( $field['enable_min_max'], $field['max_date'] ) ? $field['max_date'] : '';
408 }
409
410 // Input primary: data-date-format and value.
411 switch ( $field['datetime_format'] ) {
412 case 'date':
413 $properties['inputs']['primary']['attr']['value'] = isset( $field['date_default'] ) ? esc_attr( date( $field['date_format'] ) ) : ''; // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
414 $properties['inputs']['primary']['attr']['data-date-format'] = ! empty( $field['date_format'] ) ? str_replace( 'g:i A', 'h:i K', esc_attr( $field['date_format'] ) ) : '';
415 break;
416 case 'time':
417 $properties['inputs']['primary']['attr']['value'] = '';
418 $properties['inputs']['primary']['attr']['data-date-format'] = ! empty( $field['time_format'] ) ? str_replace( 'g:i A', 'h:i K', esc_attr( $field['time_format'] ) ) : 'g:i A';
419 break;
420 case 'date-time':
421 if ( ! empty( $field['time_format'] ) ) {
422 $date_format = esc_attr( $field['date_format'] ) . ' ' . esc_attr( $field['time_format'] );
423 $properties['inputs']['primary']['attr']['value'] = isset( $field['date_default'] ) ? esc_attr( date( $date_format ) ) : ''; // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
424 $properties['inputs']['primary']['attr']['data-date-format'] = ! empty( $field['date_format'] ) ? str_replace( 'g:i A', 'h:i K', esc_attr( $date_format ) ) : '';
425 } else {
426 $date_format = esc_attr( $field['date_format'] ) . ' g:i A';
427 $properties['inputs']['primary']['attr']['value'] = isset( $field['date_default'] ) ? esc_attr( date( $date_format ) ) : ''; // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
428 $properties['inputs']['primary']['attr']['data-date-format'] = ! empty( $field['date_format'] ) ? str_replace( 'g:i A', 'h:i K', esc_attr( $date_format ) ) : '';
429 }
430 break;
431 }
432 }
433 return $properties;
434 }
435
436 /**
437 * Field preview inside the builder.
438 *
439 * @since 1.0.0
440 * @param array $field Field Data.
441 */
442 public function field_preview( $field ) {
443 // Define data.
444 $placeholder = ! empty( $field['placeholder'] ) ? esc_attr( $field['placeholder'] ) : '';
445
446 // Label.
447 $this->field_preview_option( 'label', $field );
448
449 // Primary input.
450 echo '<input type="text" placeholder="' . esc_attr( $placeholder ) . '" class="widefat" disabled>';
451
452 // Description.
453 $this->field_preview_option( 'description', $field );
454 }
455
456 /**
457 * Field display on the form front-end.
458 *
459 * @since 1.0.0
460 *
461 * @param array $field Field Data.
462 * @param array $deprecated Deprecated Parameter.
463 * @param array $form_data Form Data.
464 */
465 public function field_display( $field, $deprecated, $form_data ) {
466 // Define data.
467 $primary = $field['properties']['inputs']['primary'];
468
469 $class = array_merge( array( 'flatpickr-field' ), $primary['class'] );
470
471 // Primary field.
472 printf(
473 '<input type="text" %s %s >',
474 evf_html_attributes( $primary['id'], $class, $primary['data'], $primary['attr'] ),
475 esc_attr( $primary['required'] )
476 );
477 }
478
479 /**
480 * Register/queue frontend scripts.
481 *
482 * @param array $atts Shortcode attributes.
483 */
484 public static function load_assets( $atts ) {
485 $form_id = isset( $atts['id'] ) ? wp_unslash( $atts['id'] ) : ''; // WPCS: CSRF ok, input var ok, sanitization ok.
486 $form_obj = evf()->form->get( $form_id );
487 $form_data = ! empty( $form_obj->post_content ) ? evf_decode( $form_obj->post_content ) : '';
488 $data_i10n = 'en';
489
490 if ( ! empty( $form_data['form_fields'] ) ) {
491 foreach ( $form_data['form_fields'] as $form_field ) {
492 if ( 'date-time' === $form_field['type'] ) {
493 $data_i10n = isset( $form_field['date_localization'] ) ? $form_field['date_localization'] : 'en';
494 }
495 }
496 }
497
498 if ( wp_script_is( 'flatpickr' ) && 'en' !== $data_i10n ) {
499 wp_enqueue_script( 'flatpickr-localization', 'https://npmcdn.com/flatpickr/dist/l10n/' . $data_i10n . '.js', array(), EVF_VERSION, true );
500 }
501 }
502 }
503