PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.4.4
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.4.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-date.php

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

128 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Date Field Class
5 */
6 class WeForms_Form_Field_Date_Free extends WeForms_Field_Contract {
7
8 public function __construct() {
9 $this->name = __( 'Date / Time', 'weforms' );
10 $this->input_type = 'date_field';
11 $this->icon = 'calendar-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 $value = ''; ?>
24 <li <?php $this->print_list_attributes( $field_settings ); ?>>
25 <?php $this->print_label( $field_settings ); ?>
26
27 <div class="wpuf-fields">
28 <input id="wpuf-date-<?php echo esc_attr( $field_settings['name'] ); ?>" type="text" class="datepicker <?php echo ' wpuf_'.esc_attr( $field_settings['name'] ).'_'. esc_attr($form_id); ?>" data-required="<?php echo esc_attr($field_settings['required']) ?>" data-type="text" name="<?php echo esc_attr( $field_settings['name'] ); ?>" placeholder="<?php echo esc_attr( $field_settings['format'] ); ?>" value="<?php echo esc_attr( $value ) ?>" size="30" />
29 <?php $this->help_text( $field_settings ); ?>
30 </div>
31 <script type="text/javascript">
32 jQuery(function($) {
33 <?php if ( $field_settings['time'] == 'yes' ) { ?>
34 $("#wpuf-date-<?php echo esc_attr($field_settings['name']); ?>").datetimepicker({ dateFormat: '<?php echo esc_attr($field_settings["format"]); ?>' });
35 <?php } else { ?>
36 $("#wpuf-date-<?php echo esc_attr($field_settings['name']); ?>").datepicker({ dateFormat: '<?php echo esc_attr($field_settings["format"]); ?>' });
37 <?php } ?>
38 });
39 </script>
40
41 </li>
42 <?php
43 }
44
45 /**
46 * Get field options setting
47 *
48 * @return array
49 */
50 public function get_options_settings() {
51 $default_options = $this->get_default_option_settings();
52
53 $settings = [
54 [
55 'name' => 'format',
56 'title' => __( 'Date Format', 'weforms' ),
57 'type' => 'text',
58 'section' => 'advanced',
59 'priority' => 23,
60 'help_text' => __( 'The date format', 'weforms' ),
61 ],
62 [
63 'name' => 'time',
64 'title' => '',
65 'type' => 'checkbox',
66 'is_single_opt' => true,
67 'options' => [
68 'yes' => __( 'Enable time input', 'weforms' ),
69 ],
70 'section' => 'advanced',
71 'priority' => 24,
72 'help_text' => '',
73 ],
74 [
75 'name' => 'is_publish_time',
76 'title' => '',
77 'type' => 'checkbox',
78 'is_single_opt' => true,
79 'options' => [
80 'yes' => __( 'Set this as publish time input', 'weforms' ),
81 ],
82 'section' => 'advanced',
83 'priority' => 24,
84 'help_text' => '',
85 ],
86 ];
87
88 return array_merge( $default_options, $settings );
89 }
90
91 /**
92 * Get the field props
93 *
94 * @return array
95 */
96 public function get_field_props() {
97 $defaults = $this->default_attributes();
98 $props = [
99 'format' => 'dd/mm/yy',
100 'time' => '',
101 'is_publish_time' => '',
102 ];
103
104 return array_merge( $defaults, $props );
105 }
106
107 /**
108 * Prepare entry
109 *
110 * @param $field
111 *
112 * @return mixed
113 */
114 public function prepare_entry( $field, $args = [] ) {
115 if( empty( $_POST['_wpnonce'] ) ) {
116 wp_send_json_error( __( 'Unauthorized operation', 'weforms' ) );
117 }
118
119 if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ), 'wpuf_form_add' ) ) {
120 wp_send_json_error( __( 'Unauthorized operation', 'weforms' ) );
121 }
122
123 $args = ! empty( $args ) ? $args : weforms_clean( $_POST );
124
125 return sanitize_text_field( trim( $args[$field['name']] ) );
126 }
127 }
128