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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
acceptance.php 7 years ago akismet.php 7 years ago checkbox.php 7 years ago constant-contact.php 7 years ago count.php 7 years ago date.php 7 years ago file.php 7 years ago flamingo.php 7 years ago hidden.php 7 years ago listo.php 9 years ago number.php 7 years ago quiz.php 7 years ago really-simple-captcha.php 7 years ago recaptcha.php 7 years ago response.php 7 years ago select.php 7 years ago submit.php 7 years ago text.php 7 years ago textarea.php 7 years ago
number.php
234 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', array( 'name-attr' => true ) );
15 }
16
17 function wpcf7_number_form_tag_handler( $tag ) {
18 if ( empty( $tag->name ) ) {
19 return '';
20 }
21
22 $validation_error = wpcf7_get_validation_error( $tag->name );
23
24 $class = wpcf7_form_controls_class( $tag->type );
25
26 $class .= ' wpcf7-validates-as-number';
27
28 if ( $validation_error ) {
29 $class .= ' wpcf7-not-valid';
30 }
31
32 $atts = array();
33
34 $atts['class'] = $tag->get_class_option( $class );
35 $atts['id'] = $tag->get_id_option();
36 $atts['tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true );
37 $atts['min'] = $tag->get_option( 'min', 'signed_int', true );
38 $atts['max'] = $tag->get_option( 'max', 'signed_int', true );
39 $atts['step'] = $tag->get_option( 'step', 'int', true );
40
41 if ( $tag->has_option( 'readonly' ) ) {
42 $atts['readonly'] = 'readonly';
43 }
44
45 if ( $tag->is_required() ) {
46 $atts['aria-required'] = 'true';
47 }
48
49 $atts['aria-invalid'] = $validation_error ? 'true' : 'false';
50
51 $value = (string) reset( $tag->values );
52
53 if ( $tag->has_option( 'placeholder' )
54 or $tag->has_option( 'watermark' ) ) {
55 $atts['placeholder'] = $value;
56 $value = '';
57 }
58
59 $value = $tag->get_default_option( $value );
60
61 $value = wpcf7_get_hangover( $tag->name, $value );
62
63 $atts['value'] = $value;
64
65 if ( wpcf7_support_html5() ) {
66 $atts['type'] = $tag->basetype;
67 } else {
68 $atts['type'] = 'text';
69 }
70
71 $atts['name'] = $tag->name;
72
73 $atts = wpcf7_format_atts( $atts );
74
75 $html = sprintf(
76 '<span class="wpcf7-form-control-wrap %1$s"><input %2$s />%3$s</span>',
77 sanitize_html_class( $tag->name ), $atts, $validation_error );
78
79 return $html;
80 }
81
82
83 /* Validation filter */
84
85 add_filter( 'wpcf7_validate_number', 'wpcf7_number_validation_filter', 10, 2 );
86 add_filter( 'wpcf7_validate_number*', 'wpcf7_number_validation_filter', 10, 2 );
87 add_filter( 'wpcf7_validate_range', 'wpcf7_number_validation_filter', 10, 2 );
88 add_filter( 'wpcf7_validate_range*', 'wpcf7_number_validation_filter', 10, 2 );
89
90 function wpcf7_number_validation_filter( $result, $tag ) {
91 $name = $tag->name;
92
93 $value = isset( $_POST[$name] )
94 ? trim( strtr( (string) $_POST[$name], "\n", " " ) )
95 : '';
96
97 $min = $tag->get_option( 'min', 'signed_int', true );
98 $max = $tag->get_option( 'max', 'signed_int', true );
99
100 if ( $tag->is_required() and '' == $value ) {
101 $result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
102 } elseif ( '' != $value and ! wpcf7_is_number( $value ) ) {
103 $result->invalidate( $tag, wpcf7_get_message( 'invalid_number' ) );
104 } elseif ( '' != $value and '' != $min and (float) $value < (float) $min ) {
105 $result->invalidate( $tag, wpcf7_get_message( 'number_too_small' ) );
106 } elseif ( '' != $value and '' != $max and (float) $max < (float) $value ) {
107 $result->invalidate( $tag, wpcf7_get_message( 'number_too_large' ) );
108 }
109
110 return $result;
111 }
112
113
114 /* Messages */
115
116 add_filter( 'wpcf7_messages', 'wpcf7_number_messages', 10, 1 );
117
118 function wpcf7_number_messages( $messages ) {
119 return array_merge( $messages, array(
120 'invalid_number' => array(
121 'description' => __( "Number format that the sender entered is invalid", 'contact-form-7' ),
122 'default' => __( "The number format is invalid.", 'contact-form-7' )
123 ),
124
125 'number_too_small' => array(
126 'description' => __( "Number is smaller than minimum limit", 'contact-form-7' ),
127 'default' => __( "The number is smaller than the minimum allowed.", 'contact-form-7' )
128 ),
129
130 'number_too_large' => array(
131 'description' => __( "Number is larger than maximum limit", 'contact-form-7' ),
132 'default' => __( "The number is larger than the maximum allowed.", 'contact-form-7' )
133 ),
134 ) );
135 }
136
137
138 /* Tag generator */
139
140 add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_number', 18, 0 );
141
142 function wpcf7_add_tag_generator_number() {
143 $tag_generator = WPCF7_TagGenerator::get_instance();
144 $tag_generator->add( 'number', __( 'number', 'contact-form-7' ),
145 'wpcf7_tag_generator_number' );
146 }
147
148 function wpcf7_tag_generator_number( $contact_form, $args = '' ) {
149 $args = wp_parse_args( $args, array() );
150 $type = 'number';
151
152 $description = __( "Generate a form-tag for a field for numeric value input. For more details, see %s.", 'contact-form-7' );
153
154 $desc_link = wpcf7_link( __( 'https://contactform7.com/number-fields/', 'contact-form-7' ), __( 'Number Fields', 'contact-form-7' ) );
155
156 ?>
157 <div class="control-box">
158 <fieldset>
159 <legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
160
161 <table class="form-table">
162 <tbody>
163 <tr>
164 <th scope="row"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></th>
165 <td>
166 <fieldset>
167 <legend class="screen-reader-text"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></legend>
168 <select name="tagtype">
169 <option value="number" selected="selected"><?php echo esc_html( __( 'Spinbox', 'contact-form-7' ) ); ?></option>
170 <option value="range"><?php echo esc_html( __( 'Slider', 'contact-form-7' ) ); ?></option>
171 </select>
172 <br />
173 <label><input type="checkbox" name="required" /> <?php echo esc_html( __( 'Required field', 'contact-form-7' ) ); ?></label>
174 </fieldset>
175 </td>
176 </tr>
177
178 <tr>
179 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
180 <td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
181 </tr>
182
183 <tr>
184 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-values' ); ?>"><?php echo esc_html( __( 'Default value', 'contact-form-7' ) ); ?></label></th>
185 <td><input type="text" name="values" class="oneline" id="<?php echo esc_attr( $args['content'] . '-values' ); ?>" /><br />
186 <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>
187 </tr>
188
189 <tr>
190 <th scope="row"><?php echo esc_html( __( 'Range', 'contact-form-7' ) ); ?></th>
191 <td>
192 <fieldset>
193 <legend class="screen-reader-text"><?php echo esc_html( __( 'Range', 'contact-form-7' ) ); ?></legend>
194 <label>
195 <?php echo esc_html( __( 'Min', 'contact-form-7' ) ); ?>
196 <input type="number" name="min" class="numeric option" />
197 </label>
198 &ndash;
199 <label>
200 <?php echo esc_html( __( 'Max', 'contact-form-7' ) ); ?>
201 <input type="number" name="max" class="numeric option" />
202 </label>
203 </fieldset>
204 </td>
205 </tr>
206
207 <tr>
208 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
209 <td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
210 </tr>
211
212 <tr>
213 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
214 <td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
215 </tr>
216 </tbody>
217 </table>
218 </fieldset>
219 </div>
220
221 <div class="insert-box">
222 <input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()" />
223
224 <div class="submitbox">
225 <input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
226 </div>
227
228 <br class="clear" />
229
230 <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>
231 </div>
232 <?php
233 }
234