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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 11 months ago constant-contact 9 months ago recaptcha 9 months ago sendinblue 9 months ago stripe 9 months ago turnstile 9 months ago acceptance.php 11 months ago checkbox.php 9 months ago count.php 1 year ago date.php 9 months ago disallowed-list.php 9 months ago doi-helper.php 4 years ago file.php 11 months ago flamingo.php 9 months ago hidden.php 7 years ago listo.php 2 years ago number.php 9 months ago quiz.php 11 months ago really-simple-captcha.php 9 months ago reflection.php 3 years ago response.php 6 years ago select.php 9 months ago submit.php 11 months ago text.php 9 months ago textarea.php 11 months ago
number.php
286 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
204 $tag_generator->add( 'number', __( 'number', 'contact-form-7' ),
205 'wpcf7_tag_generator_number',
206 array( 'version' => '2' )
207 );
208 }
209
210 function wpcf7_tag_generator_number( $contact_form, $options ) {
211 $field_types = array(
212 'number' => array(
213 'display_name' => __( 'Number field', 'contact-form-7' ),
214 'heading' => __( 'Number field form-tag generator', 'contact-form-7' ),
215 'description' => __( 'Generates a form-tag for a <a href="https://contactform7.com/number-fields/">number input field</a>.', 'contact-form-7' ),
216 ),
217 );
218
219 $tgg = new WPCF7_TagGeneratorGenerator( $options['content'] );
220
221 $formatter = new WPCF7_HTMLFormatter();
222
223 $formatter->append_start_tag( 'header', array(
224 'class' => 'description-box',
225 ) );
226
227 $formatter->append_start_tag( 'h3' );
228
229 $formatter->append_preformatted(
230 esc_html( $field_types['number']['heading'] )
231 );
232
233 $formatter->end_tag( 'h3' );
234
235 $formatter->append_start_tag( 'p' );
236
237 $formatter->append_preformatted(
238 wp_kses_data( $field_types['number']['description'] )
239 );
240
241 $formatter->end_tag( 'header' );
242
243 $formatter->append_start_tag( 'div', array(
244 'class' => 'control-box',
245 ) );
246
247 $formatter->call_user_func( static function () use ( $tgg, $field_types ) {
248 $tgg->print( 'field_type', array(
249 'with_required' => true,
250 'select_options' => array(
251 'number' => __( 'Spinbox', 'contact-form-7' ),
252 'range' => __( 'Slider', 'contact-form-7' ),
253 ),
254 ) );
255
256 $tgg->print( 'field_name' );
257
258 $tgg->print( 'class_attr' );
259
260 $tgg->print( 'min_max', array(
261 'title' => __( 'Range', 'contact-form-7' ),
262 'min_option' => 'min:',
263 'max_option' => 'max:',
264 ) );
265
266 $tgg->print( 'default_value', array(
267 'type' => 'number',
268 'with_placeholder' => false,
269 ) );
270 } );
271
272 $formatter->end_tag( 'div' );
273
274 $formatter->append_start_tag( 'footer', array(
275 'class' => 'insert-box',
276 ) );
277
278 $formatter->call_user_func( static function () use ( $tgg, $field_types ) {
279 $tgg->print( 'insert_box_content' );
280
281 $tgg->print( 'mail_tag_tip' );
282 } );
283
284 $formatter->print();
285 }
286