PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.6.12
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.6.12
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.12, at includes/fields/class-field-text.php

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