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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
acceptance.php 16 years ago captcha.php 16 years ago checkbox.php 16 years ago file.php 16 years ago icl.php 16 years ago quiz.php 16 years ago select.php 16 years ago submit.php 16 years ago text.php 16 years ago textarea.php 16 years ago
text.php
195 lines
1 <?php
2 /**
3 ** A base module for [text], [text*], [email], and [email*]
4 **/
5
6 /* Shortcode handler */
7
8 wpcf7_add_shortcode( 'text', 'wpcf7_text_shortcode_handler', true );
9 wpcf7_add_shortcode( 'text*', 'wpcf7_text_shortcode_handler', true );
10 wpcf7_add_shortcode( 'email', 'wpcf7_text_shortcode_handler', true );
11 wpcf7_add_shortcode( 'email*', 'wpcf7_text_shortcode_handler', true );
12
13 function wpcf7_text_shortcode_handler( $tag ) {
14 global $wpcf7_contact_form;
15
16 if ( ! is_array( $tag ) )
17 return '';
18
19 $type = $tag['type'];
20 $name = $tag['name'];
21 $options = (array) $tag['options'];
22 $values = (array) $tag['values'];
23
24 if ( empty( $name ) )
25 return '';
26
27 $atts = '';
28 $id_att = '';
29 $class_att = '';
30 $size_att = '';
31 $maxlength_att = '';
32
33 if ( 'email' == $type || 'email*' == $type )
34 $class_att .= ' wpcf7-validates-as-email';
35
36 if ( 'text*' == $type || 'email*' == $type )
37 $class_att .= ' wpcf7-validates-as-required';
38
39 foreach ( $options as $option ) {
40 if ( preg_match( '%^id:([-0-9a-zA-Z_]+)$%', $option, $matches ) ) {
41 $id_att = $matches[1];
42
43 } elseif ( preg_match( '%^class:([-0-9a-zA-Z_]+)$%', $option, $matches ) ) {
44 $class_att .= ' ' . $matches[1];
45
46 } elseif ( preg_match( '%^([0-9]*)[/x]([0-9]*)$%', $option, $matches ) ) {
47 $size_att = (int) $matches[1];
48 $maxlength_att = (int) $matches[2];
49 }
50 }
51
52 if ( $id_att )
53 $atts .= ' id="' . trim( $id_att ) . '"';
54
55 if ( $class_att )
56 $atts .= ' class="' . trim( $class_att ) . '"';
57
58 if ( $size_att )
59 $atts .= ' size="' . $size_att . '"';
60 else
61 $atts .= ' size="40"'; // default size
62
63 if ( $maxlength_att )
64 $atts .= ' maxlength="' . $maxlength_att . '"';
65
66 // Value
67 if ( is_a( $wpcf7_contact_form, 'WPCF7_ContactForm' ) && $wpcf7_contact_form->is_posted() ) {
68 if ( isset( $_POST['_wpcf7_mail_sent'] ) && $_POST['_wpcf7_mail_sent']['ok'] )
69 $value = '';
70 else
71 $value = stripslashes_deep( $_POST[$name] );
72 } else {
73 $value = $values[0];
74 }
75
76 $html = '<input type="text" name="' . $name . '" value="' . esc_attr( $value ) . '"' . $atts . ' />';
77
78 $validation_error = '';
79 if ( is_a( $wpcf7_contact_form, 'WPCF7_ContactForm' ) )
80 $validation_error = $wpcf7_contact_form->validation_error( $name );
81
82 $html = '<span class="wpcf7-form-control-wrap ' . $name . '">' . $html . $validation_error . '</span>';
83
84 return $html;
85 }
86
87
88 /* Validation filter */
89
90 add_filter( 'wpcf7_validate_text', 'wpcf7_text_validation_filter', 10, 2 );
91 add_filter( 'wpcf7_validate_text*', 'wpcf7_text_validation_filter', 10, 2 );
92 add_filter( 'wpcf7_validate_email', 'wpcf7_text_validation_filter', 10, 2 );
93 add_filter( 'wpcf7_validate_email*', 'wpcf7_text_validation_filter', 10, 2 );
94
95 function wpcf7_text_validation_filter( $result, $tag ) {
96 global $wpcf7_contact_form;
97
98 $type = $tag['type'];
99 $name = $tag['name'];
100
101 $_POST[$name] = trim( strtr( (string) $_POST[$name], "\n", " " ) );
102
103 if ( 'text*' == $type ) {
104 if ( '' == $_POST[$name] ) {
105 $result['valid'] = false;
106 $result['reason'][$name] = $wpcf7_contact_form->message( 'invalid_required' );
107 }
108 }
109
110 if ( 'email' == $type || 'email*' == $type ) {
111 if ( 'email*' == $type && '' == $_POST[$name] ) {
112 $result['valid'] = false;
113 $result['reason'][$name] = $wpcf7_contact_form->message( 'invalid_required' );
114 } elseif ( '' != $_POST[$name] && ! is_email( $_POST[$name] ) ) {
115 $result['valid'] = false;
116 $result['reason'][$name] = $wpcf7_contact_form->message( 'invalid_email' );
117 }
118 }
119
120 return $result;
121 }
122
123
124 /* Tag generator */
125
126 add_action( 'admin_init', 'wpcf7_add_tag_generator_text_and_email', 15 );
127
128 function wpcf7_add_tag_generator_text_and_email() {
129 wpcf7_add_tag_generator( 'text', __( 'Text field', 'wpcf7' ),
130 'wpcf7-tg-pane-text', 'wpcf7_tg_pane_text' );
131
132 wpcf7_add_tag_generator( 'email', __( 'Email field', 'wpcf7' ),
133 'wpcf7-tg-pane-email', 'wpcf7_tg_pane_email' );
134 }
135
136 function wpcf7_tg_pane_text( &$contact_form ) {
137 wpcf7_tg_pane_text_and_email( 'text' );
138 }
139
140 function wpcf7_tg_pane_email( &$contact_form ) {
141 wpcf7_tg_pane_text_and_email( 'email' );
142 }
143
144 function wpcf7_tg_pane_text_and_email( $type = 'text' ) {
145 if ( 'email' != $type )
146 $type = 'text';
147
148 ?>
149 <div id="wpcf7-tg-pane-<?php echo $type; ?>" class="hidden">
150 <form action="">
151 <table>
152 <tr><td><input type="checkbox" name="required" />&nbsp;<?php echo esc_html( __( 'Required field?', 'wpcf7' ) ); ?></td></tr>
153 <tr><td><?php echo esc_html( __( 'Name', 'wpcf7' ) ); ?><br /><input type="text" name="name" class="tg-name oneline" /></td><td></td></tr>
154 </table>
155
156 <table>
157 <tr>
158 <td><code>id</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
159 <input type="text" name="id" class="idvalue oneline option" /></td>
160
161 <td><code>class</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
162 <input type="text" name="class" class="classvalue oneline option" /></td>
163 </tr>
164
165 <tr>
166 <td><code>size</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
167 <input type="text" name="size" class="numeric oneline option" /></td>
168
169 <td><code>maxlength</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
170 <input type="text" name="maxlength" class="numeric oneline option" /></td>
171 </tr>
172
173 <tr>
174 <td><?php echo esc_html( __( 'Akismet', 'wpcf7' ) ); ?> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
175 <?php if ( 'text' == $type ) : ?>
176 <input type="checkbox" name="akismet:author" class="exclusive option" />&nbsp;<?php echo esc_html( __( "This field requires author's name", 'wpcf7' ) ); ?><br />
177 <input type="checkbox" name="akismet:author_url" class="exclusive option" />&nbsp;<?php echo esc_html( __( "This field requires author's URL", 'wpcf7' ) ); ?>
178 <?php else : ?>
179 <input type="checkbox" name="akismet:author_email" class="option" />&nbsp;<?php echo esc_html( __( "This field requires author's email address", 'wpcf7' ) ); ?>
180 <?php endif; ?>
181 </td>
182
183 <td><?php echo esc_html( __( 'Default value', 'wpcf7' ) ); ?> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br /><input type="text" name="values" class="oneline" /></td>
184 </tr>
185 </table>
186
187 <div class="tg-tag"><?php echo esc_html( __( "Copy this code and paste it into the form left.", 'wpcf7' ) ); ?><br /><input type="text" name="<?php echo $type; ?>" class="tag" readonly="readonly" onfocus="this.select()" /></div>
188
189 <div class="tg-mail-tag"><?php echo esc_html( __( "And, put this code into the Mail fields below.", 'wpcf7' ) ); ?><br /><span class="arrow">&#11015;</span>&nbsp;<input type="text" class="mail-tag" readonly="readonly" onfocus="this.select()" /></div>
190 </form>
191 </div>
192 <?php
193 }
194
195 ?>