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