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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 / select.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
select.php
237 lines
1 <?php
2 /**
3 ** A base module for [select] and [select*]
4 **/
5
6 /* form_tag handler */
7
8 add_action( 'wpcf7_init', 'wpcf7_add_form_tag_select', 10, 0 );
9
10 function wpcf7_add_form_tag_select() {
11 wpcf7_add_form_tag( array( 'select', 'select*' ),
12 'wpcf7_select_form_tag_handler',
13 array(
14 'name-attr' => true,
15 'selectable-values' => true,
16 )
17 );
18 }
19
20 function wpcf7_select_form_tag_handler( $tag ) {
21 if ( empty( $tag->name ) ) {
22 return '';
23 }
24
25 $validation_error = wpcf7_get_validation_error( $tag->name );
26
27 $class = wpcf7_form_controls_class( $tag->type );
28
29 if ( $validation_error ) {
30 $class .= ' wpcf7-not-valid';
31 }
32
33 $atts = array();
34
35 $atts['class'] = $tag->get_class_option( $class );
36 $atts['id'] = $tag->get_id_option();
37 $atts['tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true );
38
39 if ( $tag->is_required() ) {
40 $atts['aria-required'] = 'true';
41 }
42
43 if ( $validation_error ) {
44 $atts['aria-invalid'] = 'true';
45 $atts['aria-describedby'] = wpcf7_get_validation_error_reference(
46 $tag->name
47 );
48 } else {
49 $atts['aria-invalid'] = 'false';
50 }
51
52 $multiple = $tag->has_option( 'multiple' );
53 $include_blank = $tag->has_option( 'include_blank' );
54 $first_as_label = $tag->has_option( 'first_as_label' );
55
56 if ( $tag->has_option( 'size' ) ) {
57 $size = $tag->get_option( 'size', 'int', true );
58
59 if ( $size ) {
60 $atts['size'] = $size;
61 } elseif ( $multiple ) {
62 $atts['size'] = 4;
63 } else {
64 $atts['size'] = 1;
65 }
66 }
67
68 if ( $data = (array) $tag->get_data_option() ) {
69 $tag->values = array_merge( $tag->values, array_values( $data ) );
70 $tag->labels = array_merge( $tag->labels, array_values( $data ) );
71 }
72
73 $values = $tag->values;
74 $labels = $tag->labels;
75
76 $default_choice = $tag->get_default_option( null, array(
77 'multiple' => $multiple,
78 ) );
79
80 if ( $include_blank
81 or empty( $values ) ) {
82 array_unshift( $labels, '---' );
83 array_unshift( $values, '' );
84 } elseif ( $first_as_label ) {
85 $values[0] = '';
86 }
87
88 $html = '';
89 $hangover = wpcf7_get_hangover( $tag->name );
90
91 foreach ( $values as $key => $value ) {
92 if ( $hangover ) {
93 $selected = in_array( $value, (array) $hangover, true );
94 } else {
95 $selected = in_array( $value, (array) $default_choice, true );
96 }
97
98 $item_atts = array(
99 'value' => $value,
100 'selected' => $selected ? 'selected' : '',
101 );
102
103 $item_atts = wpcf7_format_atts( $item_atts );
104
105 $label = isset( $labels[$key] ) ? $labels[$key] : $value;
106
107 $html .= sprintf(
108 '<option %1$s>%2$s</option>',
109 $item_atts,
110 esc_html( $label )
111 );
112 }
113
114 if ( $multiple ) {
115 $atts['multiple'] = 'multiple';
116 }
117
118 $atts['name'] = $tag->name . ( $multiple ? '[]' : '' );
119
120 $atts = wpcf7_format_atts( $atts );
121
122 $html = sprintf(
123 '<span class="wpcf7-form-control-wrap %1$s"><select %2$s>%3$s</select>%4$s</span>',
124 sanitize_html_class( $tag->name ), $atts, $html, $validation_error
125 );
126
127 return $html;
128 }
129
130
131 /* Validation filter */
132
133 add_filter( 'wpcf7_validate_select', 'wpcf7_select_validation_filter', 10, 2 );
134 add_filter( 'wpcf7_validate_select*', 'wpcf7_select_validation_filter', 10, 2 );
135
136 function wpcf7_select_validation_filter( $result, $tag ) {
137 $name = $tag->name;
138
139 $has_value = isset( $_POST[$name] ) && '' !== $_POST[$name];
140
141 if ( $has_value and $tag->has_option( 'multiple' ) ) {
142 $vals = array_filter( (array) $_POST[$name], function( $val ) {
143 return '' !== $val;
144 } );
145
146 $has_value = ! empty( $vals );
147 }
148
149 if ( $tag->is_required() and ! $has_value ) {
150 $result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
151 }
152
153 return $result;
154 }
155
156
157 /* Tag generator */
158
159 add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_menu', 25, 0 );
160
161 function wpcf7_add_tag_generator_menu() {
162 $tag_generator = WPCF7_TagGenerator::get_instance();
163 $tag_generator->add( 'menu', __( 'drop-down menu', 'contact-form-7' ),
164 'wpcf7_tag_generator_menu' );
165 }
166
167 function wpcf7_tag_generator_menu( $contact_form, $args = '' ) {
168 $args = wp_parse_args( $args, array() );
169
170 $description = __( "Generate a form-tag for a drop-down menu. For more details, see %s.", 'contact-form-7' );
171
172 $desc_link = wpcf7_link( __( 'https://contactform7.com/checkboxes-radio-buttons-and-menus/', 'contact-form-7' ), __( 'Checkboxes, radio buttons and menus', 'contact-form-7' ) );
173
174 ?>
175 <div class="control-box">
176 <fieldset>
177 <legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
178
179 <table class="form-table">
180 <tbody>
181 <tr>
182 <th scope="row"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></th>
183 <td>
184 <fieldset>
185 <legend class="screen-reader-text"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></legend>
186 <label><input type="checkbox" name="required" /> <?php echo esc_html( __( 'Required field', 'contact-form-7' ) ); ?></label>
187 </fieldset>
188 </td>
189 </tr>
190
191 <tr>
192 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
193 <td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
194 </tr>
195
196 <tr>
197 <th scope="row"><?php echo esc_html( __( 'Options', 'contact-form-7' ) ); ?></th>
198 <td>
199 <fieldset>
200 <legend class="screen-reader-text"><?php echo esc_html( __( 'Options', 'contact-form-7' ) ); ?></legend>
201 <textarea name="values" class="values" id="<?php echo esc_attr( $args['content'] . '-values' ); ?>"></textarea>
202 <label for="<?php echo esc_attr( $args['content'] . '-values' ); ?>"><span class="description"><?php echo esc_html( __( "One option per line.", 'contact-form-7' ) ); ?></span></label><br />
203 <label><input type="checkbox" name="multiple" class="option" /> <?php echo esc_html( __( 'Allow multiple selections', 'contact-form-7' ) ); ?></label><br />
204 <label><input type="checkbox" name="include_blank" class="option" /> <?php echo esc_html( __( 'Insert a blank item as the first option', 'contact-form-7' ) ); ?></label>
205 </fieldset>
206 </td>
207 </tr>
208
209 <tr>
210 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
211 <td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
212 </tr>
213
214 <tr>
215 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
216 <td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
217 </tr>
218
219 </tbody>
220 </table>
221 </fieldset>
222 </div>
223
224 <div class="insert-box">
225 <input type="text" name="select" class="tag code" readonly="readonly" onfocus="this.select()" />
226
227 <div class="submitbox">
228 <input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
229 </div>
230
231 <br class="clear" />
232
233 <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>
234 </div>
235 <?php
236 }
237