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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
akismet 3 years ago constant-contact 3 years ago recaptcha 3 years ago sendinblue 3 years ago stripe 3 years ago acceptance.php 3 years ago checkbox.php 3 years ago count.php 3 years ago date.php 3 years ago disallowed-list.php 4 years ago doi-helper.php 4 years ago file.php 3 years ago flamingo.php 3 years ago hidden.php 7 years ago listo.php 9 years ago number.php 3 years ago quiz.php 4 years ago really-simple-captcha.php 3 years ago reflection.php 3 years ago response.php 6 years ago select.php 3 years ago submit.php 4 years ago text.php 3 years ago textarea.php 3 years ago
select.php
232 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(
83 $labels,
84 __( '&#8212;Please choose an option&#8212;', 'contact-form-7' )
85 );
86 array_unshift( $values, '' );
87 } elseif ( $first_as_label ) {
88 $values[0] = '';
89 }
90
91 $html = '';
92 $hangover = wpcf7_get_hangover( $tag->name );
93
94 foreach ( $values as $key => $value ) {
95 if ( $hangover ) {
96 $selected = in_array( $value, (array) $hangover, true );
97 } else {
98 $selected = in_array( $value, (array) $default_choice, true );
99 }
100
101 $item_atts = array(
102 'value' => $value,
103 'selected' => $selected,
104 );
105
106 $label = isset( $labels[$key] ) ? $labels[$key] : $value;
107
108 $html .= sprintf(
109 '<option %1$s>%2$s</option>',
110 wpcf7_format_atts( $item_atts ),
111 esc_html( $label )
112 );
113 }
114
115 $atts['multiple'] = (bool) $multiple;
116 $atts['name'] = $tag->name . ( $multiple ? '[]' : '' );
117
118 $html = sprintf(
119 '<span class="wpcf7-form-control-wrap" data-name="%1$s"><select %2$s>%3$s</select>%4$s</span>',
120 esc_attr( $tag->name ),
121 wpcf7_format_atts( $atts ),
122 $html,
123 $validation_error
124 );
125
126 return $html;
127 }
128
129
130 add_action(
131 'wpcf7_swv_create_schema',
132 'wpcf7_swv_add_select_rules',
133 10, 2
134 );
135
136 function wpcf7_swv_add_select_rules( $schema, $contact_form ) {
137 $tags = $contact_form->scan_form_tags( array(
138 'type' => array( 'select*' ),
139 ) );
140
141 foreach ( $tags as $tag ) {
142 $schema->add_rule(
143 wpcf7_swv_create_rule( 'required', array(
144 'field' => $tag->name,
145 'error' => wpcf7_get_message( 'invalid_required' ),
146 ) )
147 );
148 }
149 }
150
151
152 /* Tag generator */
153
154 add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_menu', 25, 0 );
155
156 function wpcf7_add_tag_generator_menu() {
157 $tag_generator = WPCF7_TagGenerator::get_instance();
158 $tag_generator->add( 'menu', __( 'drop-down menu', 'contact-form-7' ),
159 'wpcf7_tag_generator_menu' );
160 }
161
162 function wpcf7_tag_generator_menu( $contact_form, $args = '' ) {
163 $args = wp_parse_args( $args, array() );
164
165 $description = __( "Generate a form-tag for a drop-down menu. For more details, see %s.", 'contact-form-7' );
166
167 $desc_link = wpcf7_link( __( 'https://contactform7.com/checkboxes-radio-buttons-and-menus/', 'contact-form-7' ), __( 'Checkboxes, radio buttons and menus', 'contact-form-7' ) );
168
169 ?>
170 <div class="control-box">
171 <fieldset>
172 <legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
173
174 <table class="form-table">
175 <tbody>
176 <tr>
177 <th scope="row"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></th>
178 <td>
179 <fieldset>
180 <legend class="screen-reader-text"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></legend>
181 <label><input type="checkbox" name="required" /> <?php echo esc_html( __( 'Required field', 'contact-form-7' ) ); ?></label>
182 </fieldset>
183 </td>
184 </tr>
185
186 <tr>
187 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
188 <td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
189 </tr>
190
191 <tr>
192 <th scope="row"><?php echo esc_html( __( 'Options', 'contact-form-7' ) ); ?></th>
193 <td>
194 <fieldset>
195 <legend class="screen-reader-text"><?php echo esc_html( __( 'Options', 'contact-form-7' ) ); ?></legend>
196 <textarea name="values" class="values" id="<?php echo esc_attr( $args['content'] . '-values' ); ?>"></textarea>
197 <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 />
198 <label><input type="checkbox" name="multiple" class="option" /> <?php echo esc_html( __( 'Allow multiple selections', 'contact-form-7' ) ); ?></label><br />
199 <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>
200 </fieldset>
201 </td>
202 </tr>
203
204 <tr>
205 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
206 <td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
207 </tr>
208
209 <tr>
210 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
211 <td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
212 </tr>
213
214 </tbody>
215 </table>
216 </fieldset>
217 </div>
218
219 <div class="insert-box">
220 <input type="text" name="select" class="tag code" readonly="readonly" onfocus="this.select()" />
221
222 <div class="submitbox">
223 <input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
224 </div>
225
226 <br class="clear" />
227
228 <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>
229 </div>
230 <?php
231 }
232