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

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

151 lines 5.6 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_Text extends WeForms_Field_Contract {
7
8 public function __construct() {
9 $this->name = __( 'Text', 'weforms' );
10 $this->input_type = 'text_field';
11 $this->icon = 'text-width';
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 = $field_settings['default']; ?>
24 <li <?php $this->print_list_attributes( $field_settings ); ?>>
25 <?php $this->print_label( $field_settings, $form_id ); ?>
26
27 <div class="wpuf-fields">
28 <input
29 class="textfield <?php echo 'wpuf_' . esc_attr( $field_settings['name'] ) . '_' . esc_attr( $form_id ); ?>"
30 id="<?php echo esc_attr( $field_settings['name'] ) . '_' . esc_attr( $form_id ); ?>"
31 type="text"
32 data-duplicate="<?php echo esc_attr( $field_settings['duplicate'] ) ? esc_attr( $field_settings['duplicate'] ) : 'no'; ?>"
33 data-required="<?php echo esc_attr( $field_settings['required'] ) ?>"
34 data-type="text" name="<?php echo esc_attr( $field_settings['name'] ); ?>"
35 placeholder="<?php echo esc_attr( $field_settings['placeholder'] ); ?>"
36 value="<?php echo esc_attr( $value ); ?>"
37 size="<?php echo esc_attr( $field_settings['size'] ); ?>"
38 />
39
40 <span class="wpuf-wordlimit-message wpuf-help"></span>
41 <?php $this->help_text( $field_settings ); ?>
42 </div>
43 <?php
44 if ( isset( $field_settings['word_restriction'] ) && $field_settings['word_restriction'] ) {
45 $this->check_word_restriction_func(
46 $field_settings['word_restriction'],
47 'no',
48 $field_settings['name'] . '_' . $form_id
49 );
50 }
51
52 $mask_option = isset( $field_settings['mask_options'] ) ? $field_settings['mask_options'] : '';
53
54 if ( $mask_option ) {
55 ?>
56 <script>
57 jQuery(document).ready(function($) {
58 var text_field = $( "input[name*=<?php echo esc_attr( $field_settings['name'] ); ?>]" );
59 switch ( '<?php echo esc_attr( $mask_option ); ?>' ) {
60 case 'us_phone':
61 text_field.mask('(999) 999-9999');
62 break;
63 case 'date':
64 text_field.mask('99/99/9999');
65 break;
66 case 'tax_id':
67 text_field.mask('99-9999999');
68 break;
69 case 'ssn':
70 text_field.mask('999-99-9999');
71 break;
72 case 'zip':
73 text_field.mask('99999');
74 break;
75 default:
76 break;
77 }
78 });
79 </script>
80 <?php
81 } ?>
82 </li>
83 <?php
84 }
85
86 /**
87 * Get field options setting
88 *
89 * @return array
90 */
91 public function get_options_settings() {
92 $default_options = $this->get_default_option_settings();
93 $default_text_options = $this->get_default_text_option_settings( true );
94 $check_duplicate = [
95 [
96 'name' => 'duplicate',
97 'title' => 'No Duplicates',
98 'type' => 'checkbox',
99 'is_single_opt' => true,
100 'options' => [
101 'no' => __( 'Unique Values Only', 'weforms' ),
102 ],
103 'default' => '',
104 'section' => 'advanced',
105 'priority' => 23,
106 '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' ),
107 ],
108 ];
109
110 $text_options = array_merge( $default_options, $default_text_options, $check_duplicate );
111
112 return apply_filters( 'weforms_text_field_option_settings', $text_options );
113 }
114
115 /**
116 * Get the field props
117 *
118 * @return array
119 */
120 public function get_field_props() {
121 $defaults = $this->default_attributes();
122 $props = [
123 'word_restriction' => '',
124 'duplicate' => '',
125 ];
126
127 return array_merge( $defaults, $props );
128 }
129
130 /**
131 * Prepare entry
132 *
133 * @param $field
134 *
135 * @return mixed
136 */
137 public function prepare_entry( $field, $args = [] ) {
138 if( empty( $_POST[ '_wpnonce' ] ) ) {
139 wp_send_json_error( __( 'Unauthorized operation', 'weforms' ) );
140 }
141
142 if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ), 'wpuf_form_add' ) ) {
143 wp_send_json_error( __( 'Unauthorized operation', 'weforms' ) );
144 }
145
146 $args = ! empty( $args ) ? $args : weforms_clean( $_POST );
147
148 return sanitize_text_field( trim( $args[$field['name']] ) );
149 }
150 }
151