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 3.9 3.9-beta 3.9.1 3.9.2 3.9.3 4.0 4.0.1 4.0.2 4.0.3 4.1 4.1-beta 4.1.1 4.1.2 4.2 4.2-beta 4.2.1 4.2.2 4.3 4.3.1 4.4 4.4.1 4.4.2 4.5 4.5.1 4.6 4.6.1 4.7 4.8 4.8.1 4.9 4.9.1 4.9.2 5.0 5.0.1
contact-form-7 / modules / text.php
contact-form-7 / modules Last commit date
constant-contact 4 years ago recaptcha 4 years ago sendinblue 4 years ago stripe 4 years ago acceptance.php 5 years ago akismet.php 4 years ago checkbox.php 4 years ago count.php 7 years ago date.php 5 years ago disallowed-list.php 4 years ago doi-helper.php 4 years ago file.php 5 years ago flamingo.php 4 years ago hidden.php 7 years ago listo.php 9 years ago number.php 5 years ago quiz.php 4 years ago really-simple-captcha.php 4 years ago response.php 6 years ago select.php 4 years ago submit.php 4 years ago text.php 4 years ago textarea.php 4 years ago
text.php
333 lines
1 <?php
2 /**
3 ** A base module for the following types of tags:
4 ** [text] and [text*] # Single-line text
5 ** [email] and [email*] # Email address
6 ** [url] and [url*] # URL
7 ** [tel] and [tel*] # Telephone number
8 **/
9
10 /* form_tag handler */
11
12 add_action( 'wpcf7_init', 'wpcf7_add_form_tag_text', 10, 0 );
13
14 function wpcf7_add_form_tag_text() {
15 wpcf7_add_form_tag(
16 array( 'text', 'text*', 'email', 'email*', 'url', 'url*', 'tel', 'tel*' ),
17 'wpcf7_text_form_tag_handler',
18 array(
19 'name-attr' => true,
20 )
21 );
22 }
23
24 function wpcf7_text_form_tag_handler( $tag ) {
25 if ( empty( $tag->name ) ) {
26 return '';
27 }
28
29 $validation_error = wpcf7_get_validation_error( $tag->name );
30
31 $class = wpcf7_form_controls_class( $tag->type, 'wpcf7-text' );
32
33 if ( in_array( $tag->basetype, array( 'email', 'url', 'tel' ) ) ) {
34 $class .= ' wpcf7-validates-as-' . $tag->basetype;
35 }
36
37 if ( $validation_error ) {
38 $class .= ' wpcf7-not-valid';
39 }
40
41 $atts = array();
42
43 $atts['size'] = $tag->get_size_option( '40' );
44 $atts['maxlength'] = $tag->get_maxlength_option();
45 $atts['minlength'] = $tag->get_minlength_option();
46
47 if ( $atts['maxlength'] and $atts['minlength']
48 and $atts['maxlength'] < $atts['minlength'] ) {
49 unset( $atts['maxlength'], $atts['minlength'] );
50 }
51
52 $atts['class'] = $tag->get_class_option( $class );
53 $atts['id'] = $tag->get_id_option();
54 $atts['tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true );
55
56 $atts['autocomplete'] = $tag->get_option( 'autocomplete',
57 '[-0-9a-zA-Z]+', true );
58
59 if ( $tag->has_option( 'readonly' ) ) {
60 $atts['readonly'] = 'readonly';
61 }
62
63 if ( $tag->is_required() ) {
64 $atts['aria-required'] = 'true';
65 }
66
67 if ( $validation_error ) {
68 $atts['aria-invalid'] = 'true';
69 $atts['aria-describedby'] = wpcf7_get_validation_error_reference(
70 $tag->name
71 );
72 } else {
73 $atts['aria-invalid'] = 'false';
74 }
75
76 $value = (string) reset( $tag->values );
77
78 if ( $tag->has_option( 'placeholder' )
79 or $tag->has_option( 'watermark' ) ) {
80 $atts['placeholder'] = $value;
81 $value = '';
82 }
83
84 $value = $tag->get_default_option( $value );
85
86 $value = wpcf7_get_hangover( $tag->name, $value );
87
88 $atts['value'] = $value;
89
90 if ( wpcf7_support_html5() ) {
91 $atts['type'] = $tag->basetype;
92 } else {
93 $atts['type'] = 'text';
94 }
95
96 $atts['name'] = $tag->name;
97
98 $atts = wpcf7_format_atts( $atts );
99
100 $html = sprintf(
101 '<span class="wpcf7-form-control-wrap %1$s"><input %2$s />%3$s</span>',
102 sanitize_html_class( $tag->name ), $atts, $validation_error
103 );
104
105 return $html;
106 }
107
108
109 /* Validation filter */
110
111 add_filter( 'wpcf7_validate_text', 'wpcf7_text_validation_filter', 10, 2 );
112 add_filter( 'wpcf7_validate_text*', 'wpcf7_text_validation_filter', 10, 2 );
113 add_filter( 'wpcf7_validate_email', 'wpcf7_text_validation_filter', 10, 2 );
114 add_filter( 'wpcf7_validate_email*', 'wpcf7_text_validation_filter', 10, 2 );
115 add_filter( 'wpcf7_validate_url', 'wpcf7_text_validation_filter', 10, 2 );
116 add_filter( 'wpcf7_validate_url*', 'wpcf7_text_validation_filter', 10, 2 );
117 add_filter( 'wpcf7_validate_tel', 'wpcf7_text_validation_filter', 10, 2 );
118 add_filter( 'wpcf7_validate_tel*', 'wpcf7_text_validation_filter', 10, 2 );
119
120 function wpcf7_text_validation_filter( $result, $tag ) {
121 $name = $tag->name;
122
123 $value = isset( $_POST[$name] )
124 ? trim( wp_unslash( strtr( (string) $_POST[$name], "\n", " " ) ) )
125 : '';
126
127 if ( 'text' == $tag->basetype ) {
128 if ( $tag->is_required() and '' === $value ) {
129 $result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
130 }
131 }
132
133 if ( 'email' == $tag->basetype ) {
134 if ( $tag->is_required() and '' === $value ) {
135 $result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
136 } elseif ( '' !== $value and ! wpcf7_is_email( $value ) ) {
137 $result->invalidate( $tag, wpcf7_get_message( 'invalid_email' ) );
138 }
139 }
140
141 if ( 'url' == $tag->basetype ) {
142 if ( $tag->is_required() and '' === $value ) {
143 $result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
144 } elseif ( '' !== $value and ! wpcf7_is_url( $value ) ) {
145 $result->invalidate( $tag, wpcf7_get_message( 'invalid_url' ) );
146 }
147 }
148
149 if ( 'tel' == $tag->basetype ) {
150 if ( $tag->is_required() and '' === $value ) {
151 $result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
152 } elseif ( '' !== $value and ! wpcf7_is_tel( $value ) ) {
153 $result->invalidate( $tag, wpcf7_get_message( 'invalid_tel' ) );
154 }
155 }
156
157 if ( '' !== $value ) {
158 $maxlength = $tag->get_maxlength_option();
159 $minlength = $tag->get_minlength_option();
160
161 if ( $maxlength and $minlength and $maxlength < $minlength ) {
162 $maxlength = $minlength = null;
163 }
164
165 $code_units = wpcf7_count_code_units( $value );
166
167 if ( false !== $code_units ) {
168 if ( $maxlength and $maxlength < $code_units ) {
169 $result->invalidate( $tag, wpcf7_get_message( 'invalid_too_long' ) );
170 } elseif ( $minlength and $code_units < $minlength ) {
171 $result->invalidate( $tag, wpcf7_get_message( 'invalid_too_short' ) );
172 }
173 }
174 }
175
176 return $result;
177 }
178
179
180 /* Messages */
181
182 add_filter( 'wpcf7_messages', 'wpcf7_text_messages', 10, 1 );
183
184 function wpcf7_text_messages( $messages ) {
185 $messages = array_merge( $messages, array(
186 'invalid_email' => array(
187 'description' =>
188 __( "Email address that the sender entered is invalid", 'contact-form-7' ),
189 'default' =>
190 __( "The e-mail address entered is invalid.", 'contact-form-7' ),
191 ),
192
193 'invalid_url' => array(
194 'description' =>
195 __( "URL that the sender entered is invalid", 'contact-form-7' ),
196 'default' =>
197 __( "The URL is invalid.", 'contact-form-7' ),
198 ),
199
200 'invalid_tel' => array(
201 'description' =>
202 __( "Telephone number that the sender entered is invalid", 'contact-form-7' ),
203 'default' =>
204 __( "The telephone number is invalid.", 'contact-form-7' ),
205 ),
206 ) );
207
208 return $messages;
209 }
210
211
212 /* Tag generator */
213
214 add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_text', 15, 0 );
215
216 function wpcf7_add_tag_generator_text() {
217 $tag_generator = WPCF7_TagGenerator::get_instance();
218 $tag_generator->add( 'text', __( 'text', 'contact-form-7' ),
219 'wpcf7_tag_generator_text' );
220 $tag_generator->add( 'email', __( 'email', 'contact-form-7' ),
221 'wpcf7_tag_generator_text' );
222 $tag_generator->add( 'url', __( 'URL', 'contact-form-7' ),
223 'wpcf7_tag_generator_text' );
224 $tag_generator->add( 'tel', __( 'tel', 'contact-form-7' ),
225 'wpcf7_tag_generator_text' );
226 }
227
228 function wpcf7_tag_generator_text( $contact_form, $args = '' ) {
229 $args = wp_parse_args( $args, array() );
230 $type = $args['id'];
231
232 if ( ! in_array( $type, array( 'email', 'url', 'tel' ) ) ) {
233 $type = 'text';
234 }
235
236 if ( 'text' == $type ) {
237 $description = __( "Generate a form-tag for a single-line plain text input field. For more details, see %s.", 'contact-form-7' );
238 } elseif ( 'email' == $type ) {
239 $description = __( "Generate a form-tag for a single-line email address input field. For more details, see %s.", 'contact-form-7' );
240 } elseif ( 'url' == $type ) {
241 $description = __( "Generate a form-tag for a single-line URL input field. For more details, see %s.", 'contact-form-7' );
242 } elseif ( 'tel' == $type ) {
243 $description = __( "Generate a form-tag for a single-line telephone number input field. For more details, see %s.", 'contact-form-7' );
244 }
245
246 $desc_link = wpcf7_link( __( 'https://contactform7.com/text-fields/', 'contact-form-7' ), __( 'Text fields', 'contact-form-7' ) );
247
248 ?>
249 <div class="control-box">
250 <fieldset>
251 <legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
252
253 <table class="form-table">
254 <tbody>
255 <tr>
256 <th scope="row"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></th>
257 <td>
258 <fieldset>
259 <legend class="screen-reader-text"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></legend>
260 <label><input type="checkbox" name="required" /> <?php echo esc_html( __( 'Required field', 'contact-form-7' ) ); ?></label>
261 </fieldset>
262 </td>
263 </tr>
264
265 <tr>
266 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
267 <td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
268 </tr>
269
270 <tr>
271 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-values' ); ?>"><?php echo esc_html( __( 'Default value', 'contact-form-7' ) ); ?></label></th>
272 <td><input type="text" name="values" class="oneline" id="<?php echo esc_attr( $args['content'] . '-values' ); ?>" /><br />
273 <label><input type="checkbox" name="placeholder" class="option" /> <?php echo esc_html( __( 'Use this text as the placeholder of the field', 'contact-form-7' ) ); ?></label></td>
274 </tr>
275
276 <?php if ( in_array( $type, array( 'text', 'email', 'url' ) ) ) : ?>
277 <tr>
278 <th scope="row"><?php echo esc_html( __( 'Akismet', 'contact-form-7' ) ); ?></th>
279 <td>
280 <fieldset>
281 <legend class="screen-reader-text"><?php echo esc_html( __( 'Akismet', 'contact-form-7' ) ); ?></legend>
282
283 <?php if ( 'text' == $type ) : ?>
284 <label>
285 <input type="checkbox" name="akismet:author" class="option" />
286 <?php echo esc_html( __( "This field requires author's name", 'contact-form-7' ) ); ?>
287 </label>
288 <?php elseif ( 'email' == $type ) : ?>
289 <label>
290 <input type="checkbox" name="akismet:author_email" class="option" />
291 <?php echo esc_html( __( "This field requires author's email address", 'contact-form-7' ) ); ?>
292 </label>
293 <?php elseif ( 'url' == $type ) : ?>
294 <label>
295 <input type="checkbox" name="akismet:author_url" class="option" />
296 <?php echo esc_html( __( "This field requires author's URL", 'contact-form-7' ) ); ?>
297 </label>
298 <?php endif; ?>
299
300 </fieldset>
301 </td>
302 </tr>
303 <?php endif; ?>
304
305 <tr>
306 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
307 <td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
308 </tr>
309
310 <tr>
311 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
312 <td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
313 </tr>
314
315 </tbody>
316 </table>
317 </fieldset>
318 </div>
319
320 <div class="insert-box">
321 <input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()" />
322
323 <div class="submitbox">
324 <input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
325 </div>
326
327 <br class="clear" />
328
329 <p class="description mail-tag"><label for="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>"><?php echo sprintf( esc_html( __( "To use the value input through this field in a mail field, you need to insert the corresponding mail-tag (%s) into the field on the Mail tab.", 'contact-form-7' ) ), '<strong><span class="mail-tag"></span></strong>' ); ?><input type="text" class="mail-tag code hidden" readonly="readonly" id="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>" /></label></p>
330 </div>
331 <?php
332 }
333