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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 / number.php
contact-form-7 / modules Last commit date
akismet 2 years ago constant-contact 2 years ago recaptcha 2 years ago sendinblue 2 years ago stripe 2 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 3 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
number.php
293 lines
1 <?php
2 /**
3 ** A base module for the following types of tags:
4 ** [number] and [number*] # Number
5 ** [range] and [range*] # Range
6 **/
7
8 /* form_tag handler */
9
10 add_action( 'wpcf7_init', 'wpcf7_add_form_tag_number', 10, 0 );
11
12 function wpcf7_add_form_tag_number() {
13 wpcf7_add_form_tag( array( 'number', 'number*', 'range', 'range*' ),
14 'wpcf7_number_form_tag_handler',
15 array(
16 'name-attr' => true,
17 )
18 );
19 }
20
21 function wpcf7_number_form_tag_handler( $tag ) {
22 if ( empty( $tag->name ) ) {
23 return '';
24 }
25
26 $validation_error = wpcf7_get_validation_error( $tag->name );
27
28 $class = wpcf7_form_controls_class( $tag->type );
29
30 $class .= ' wpcf7-validates-as-number';
31
32 if ( $validation_error ) {
33 $class .= ' wpcf7-not-valid';
34 }
35
36 $atts = array();
37
38 $atts['class'] = $tag->get_class_option( $class );
39 $atts['id'] = $tag->get_id_option();
40 $atts['tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true );
41 $atts['min'] = $tag->get_option( 'min', 'signed_num', true );
42 $atts['max'] = $tag->get_option( 'max', 'signed_num', true );
43 $atts['step'] = $tag->get_option( 'step', 'num', true );
44 $atts['readonly'] = $tag->has_option( 'readonly' );
45
46 $atts['autocomplete'] = $tag->get_option(
47 'autocomplete', '[-0-9a-zA-Z]+', true
48 );
49
50 if ( $tag->is_required() ) {
51 $atts['aria-required'] = 'true';
52 }
53
54 if ( $validation_error ) {
55 $atts['aria-invalid'] = 'true';
56 $atts['aria-describedby'] = wpcf7_get_validation_error_reference(
57 $tag->name
58 );
59 } else {
60 $atts['aria-invalid'] = 'false';
61 }
62
63 $value = (string) reset( $tag->values );
64
65 if ( $tag->has_option( 'placeholder' )
66 or $tag->has_option( 'watermark' ) ) {
67 $atts['placeholder'] = $value;
68 $value = '';
69 }
70
71 $value = $tag->get_default_option( $value );
72
73 $value = wpcf7_get_hangover( $tag->name, $value );
74
75 $atts['value'] = $value;
76
77 if ( 'range' === $tag->basetype ) {
78 if ( ! wpcf7_is_number( $atts['min'] ) ) {
79 $atts['min'] = '0';
80 }
81
82 if ( ! wpcf7_is_number( $atts['max'] ) ) {
83 $atts['max'] = '100';
84 }
85
86 if ( '' === $atts['value'] ) {
87 if ( $atts['min'] < $atts['max'] ) {
88 $atts['value'] = ( $atts['min'] + $atts['max'] ) / 2;
89 } else {
90 $atts['value'] = $atts['min'];
91 }
92 }
93 }
94
95 $atts['type'] = $tag->basetype;
96 $atts['name'] = $tag->name;
97
98 $html = sprintf(
99 '<span class="wpcf7-form-control-wrap" data-name="%1$s"><input %2$s />%3$s</span>',
100 esc_attr( $tag->name ),
101 wpcf7_format_atts( $atts ),
102 $validation_error
103 );
104
105 return $html;
106 }
107
108
109 add_action(
110 'wpcf7_swv_create_schema',
111 'wpcf7_swv_add_number_rules',
112 10, 2
113 );
114
115 function wpcf7_swv_add_number_rules( $schema, $contact_form ) {
116 $tags = $contact_form->scan_form_tags( array(
117 'basetype' => array( 'number', 'range' ),
118 ) );
119
120 foreach ( $tags as $tag ) {
121 if ( $tag->is_required() ) {
122 $schema->add_rule(
123 wpcf7_swv_create_rule( 'required', array(
124 'field' => $tag->name,
125 'error' => wpcf7_get_message( 'invalid_required' ),
126 ) )
127 );
128 }
129
130 $schema->add_rule(
131 wpcf7_swv_create_rule( 'number', array(
132 'field' => $tag->name,
133 'error' => wpcf7_get_message( 'invalid_number' ),
134 ) )
135 );
136
137 $min = $tag->get_option( 'min', 'signed_num', true );
138 $max = $tag->get_option( 'max', 'signed_num', true );
139
140 if ( 'range' === $tag->basetype ) {
141 if ( ! wpcf7_is_number( $min ) ) {
142 $min = '0';
143 }
144
145 if ( ! wpcf7_is_number( $max ) ) {
146 $max = '100';
147 }
148 }
149
150 if ( wpcf7_is_number( $min ) ) {
151 $schema->add_rule(
152 wpcf7_swv_create_rule( 'minnumber', array(
153 'field' => $tag->name,
154 'threshold' => $min,
155 'error' => wpcf7_get_message( 'number_too_small' ),
156 ) )
157 );
158 }
159
160 if ( wpcf7_is_number( $max ) ) {
161 $schema->add_rule(
162 wpcf7_swv_create_rule( 'maxnumber', array(
163 'field' => $tag->name,
164 'threshold' => $max,
165 'error' => wpcf7_get_message( 'number_too_large' ),
166 ) )
167 );
168 }
169 }
170 }
171
172
173 /* Messages */
174
175 add_filter( 'wpcf7_messages', 'wpcf7_number_messages', 10, 1 );
176
177 function wpcf7_number_messages( $messages ) {
178 return array_merge( $messages, array(
179 'invalid_number' => array(
180 'description' => __( "Number format that the sender entered is invalid", 'contact-form-7' ),
181 'default' => __( "Please enter a number.", 'contact-form-7' ),
182 ),
183
184 'number_too_small' => array(
185 'description' => __( "Number is smaller than minimum limit", 'contact-form-7' ),
186 'default' => __( "This field has a too small number.", 'contact-form-7' ),
187 ),
188
189 'number_too_large' => array(
190 'description' => __( "Number is larger than maximum limit", 'contact-form-7' ),
191 'default' => __( "This field has a too large number.", 'contact-form-7' ),
192 ),
193 ) );
194 }
195
196
197 /* Tag generator */
198
199 add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_number', 18, 0 );
200
201 function wpcf7_add_tag_generator_number() {
202 $tag_generator = WPCF7_TagGenerator::get_instance();
203 $tag_generator->add( 'number', __( 'number', 'contact-form-7' ),
204 'wpcf7_tag_generator_number' );
205 }
206
207 function wpcf7_tag_generator_number( $contact_form, $args = '' ) {
208 $args = wp_parse_args( $args, array() );
209 $type = 'number';
210
211 $description = __( "Generate a form-tag for a field for numeric value input. For more details, see %s.", 'contact-form-7' );
212
213 $desc_link = wpcf7_link( __( 'https://contactform7.com/number-fields/', 'contact-form-7' ), __( 'Number fields', 'contact-form-7' ) );
214
215 ?>
216 <div class="control-box">
217 <fieldset>
218 <legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
219
220 <table class="form-table">
221 <tbody>
222 <tr>
223 <th scope="row"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></th>
224 <td>
225 <fieldset>
226 <legend class="screen-reader-text"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></legend>
227 <select name="tagtype">
228 <option value="number" selected="selected"><?php echo esc_html( __( 'Spinbox', 'contact-form-7' ) ); ?></option>
229 <option value="range"><?php echo esc_html( __( 'Slider', 'contact-form-7' ) ); ?></option>
230 </select>
231 <br />
232 <label><input type="checkbox" name="required" /> <?php echo esc_html( __( 'Required field', 'contact-form-7' ) ); ?></label>
233 </fieldset>
234 </td>
235 </tr>
236
237 <tr>
238 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
239 <td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
240 </tr>
241
242 <tr>
243 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-values' ); ?>"><?php echo esc_html( __( 'Default value', 'contact-form-7' ) ); ?></label></th>
244 <td><input type="text" name="values" class="oneline" id="<?php echo esc_attr( $args['content'] . '-values' ); ?>" /><br />
245 <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>
246 </tr>
247
248 <tr>
249 <th scope="row"><?php echo esc_html( __( 'Range', 'contact-form-7' ) ); ?></th>
250 <td>
251 <fieldset>
252 <legend class="screen-reader-text"><?php echo esc_html( __( 'Range', 'contact-form-7' ) ); ?></legend>
253 <label>
254 <?php echo esc_html( __( 'Min', 'contact-form-7' ) ); ?>
255 <input type="number" name="min" class="numeric option" />
256 </label>
257 &ndash;
258 <label>
259 <?php echo esc_html( __( 'Max', 'contact-form-7' ) ); ?>
260 <input type="number" name="max" class="numeric option" />
261 </label>
262 </fieldset>
263 </td>
264 </tr>
265
266 <tr>
267 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
268 <td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
269 </tr>
270
271 <tr>
272 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
273 <td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
274 </tr>
275 </tbody>
276 </table>
277 </fieldset>
278 </div>
279
280 <div class="insert-box">
281 <input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()" />
282
283 <div class="submitbox">
284 <input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
285 </div>
286
287 <br class="clear" />
288
289 <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>
290 </div>
291 <?php
292 }
293