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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 11 years ago akismet.php 11 years ago captcha.php 11 years ago checkbox.php 11 years ago date.php 11 years ago file.php 11 years ago flamingo.php 11 years ago jetpack.php 12 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
216 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 = wpcf7_get_hangover( $tag->name, $value );
57
58 $atts['value'] = $value;
59
60 if ( wpcf7_support_html5() ) {
61 $atts['type'] = $tag->basetype;
62 } else {
63 $atts['type'] = 'text';
64 }
65
66 $atts['name'] = $tag->name;
67
68 $atts = wpcf7_format_atts( $atts );
69
70 $html = sprintf(
71 '<span class="wpcf7-form-control-wrap %1$s"><input %2$s />%3$s</span>',
72 sanitize_html_class( $tag->name ), $atts, $validation_error );
73
74 return $html;
75 }
76
77
78 /* Validation filter */
79
80 add_filter( 'wpcf7_validate_number', 'wpcf7_number_validation_filter', 10, 2 );
81 add_filter( 'wpcf7_validate_number*', 'wpcf7_number_validation_filter', 10, 2 );
82 add_filter( 'wpcf7_validate_range', 'wpcf7_number_validation_filter', 10, 2 );
83 add_filter( 'wpcf7_validate_range*', 'wpcf7_number_validation_filter', 10, 2 );
84
85 function wpcf7_number_validation_filter( $result, $tag ) {
86 $tag = new WPCF7_Shortcode( $tag );
87
88 $name = $tag->name;
89
90 $value = isset( $_POST[$name] )
91 ? trim( strtr( (string) $_POST[$name], "\n", " " ) )
92 : '';
93
94 $min = $tag->get_option( 'min', 'signed_int', true );
95 $max = $tag->get_option( 'max', 'signed_int', true );
96
97 if ( $tag->is_required() && '' == $value ) {
98 $result['valid'] = false;
99 $result['reason'][$name] = wpcf7_get_message( 'invalid_required' );
100 } elseif ( '' != $value && ! wpcf7_is_number( $value ) ) {
101 $result['valid'] = false;
102 $result['reason'][$name] = wpcf7_get_message( 'invalid_number' );
103 } elseif ( '' != $value && '' != $min && (float) $value < (float) $min ) {
104 $result['valid'] = false;
105 $result['reason'][$name] = wpcf7_get_message( 'number_too_small' );
106 } elseif ( '' != $value && '' != $max && (float) $max < (float) $value ) {
107 $result['valid'] = false;
108 $result['reason'][$name] = wpcf7_get_message( 'number_too_large' );
109 }
110
111 if ( isset( $result['reason'][$name] ) && $id = $tag->get_id_option() ) {
112 $result['idref'][$name] = $id;
113 }
114
115 return $result;
116 }
117
118
119 /* Messages */
120
121 add_filter( 'wpcf7_messages', 'wpcf7_number_messages' );
122
123 function wpcf7_number_messages( $messages ) {
124 return array_merge( $messages, array(
125 'invalid_number' => array(
126 'description' => __( "Number format that the sender entered is invalid", 'contact-form-7' ),
127 'default' => __( 'Number format seems invalid.', 'contact-form-7' )
128 ),
129
130 'number_too_small' => array(
131 'description' => __( "Number is smaller than minimum limit", 'contact-form-7' ),
132 'default' => __( 'This number is too small.', 'contact-form-7' )
133 ),
134
135 'number_too_large' => array(
136 'description' => __( "Number is larger than maximum limit", 'contact-form-7' ),
137 'default' => __( 'This number is too large.', 'contact-form-7' )
138 ) ) );
139 }
140
141
142 /* Tag generator */
143
144 add_action( 'admin_init', 'wpcf7_add_tag_generator_number', 18 );
145
146 function wpcf7_add_tag_generator_number() {
147 if ( ! function_exists( 'wpcf7_add_tag_generator' ) )
148 return;
149
150 wpcf7_add_tag_generator( 'number', __( 'Number (spinbox)', 'contact-form-7' ),
151 'wpcf7-tg-pane-number', 'wpcf7_tg_pane_number' );
152
153 wpcf7_add_tag_generator( 'range', __( 'Number (slider)', 'contact-form-7' ),
154 'wpcf7-tg-pane-range', 'wpcf7_tg_pane_range' );
155 }
156
157 function wpcf7_tg_pane_number( $contact_form ) {
158 wpcf7_tg_pane_number_and_relatives( 'number' );
159 }
160
161 function wpcf7_tg_pane_range( $contact_form ) {
162 wpcf7_tg_pane_number_and_relatives( 'range' );
163 }
164
165 function wpcf7_tg_pane_number_and_relatives( $type = 'number' ) {
166 if ( ! in_array( $type, array( 'range' ) ) )
167 $type = 'number';
168
169 ?>
170 <div id="wpcf7-tg-pane-<?php echo $type; ?>" class="hidden">
171 <form action="">
172 <table>
173 <tr><td><input type="checkbox" name="required" />&nbsp;<?php echo esc_html( __( 'Required field?', 'contact-form-7' ) ); ?></td></tr>
174 <tr><td><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?><br /><input type="text" name="name" class="tg-name oneline" /></td><td></td></tr>
175 </table>
176
177 <table>
178 <tr>
179 <td><code>id</code> (<?php echo esc_html( __( 'optional', 'contact-form-7' ) ); ?>)<br />
180 <input type="text" name="id" class="idvalue oneline option" /></td>
181
182 <td><code>class</code> (<?php echo esc_html( __( 'optional', 'contact-form-7' ) ); ?>)<br />
183 <input type="text" name="class" class="classvalue oneline option" /></td>
184 </tr>
185
186 <tr>
187 <td><code>min</code> (<?php echo esc_html( __( 'optional', 'contact-form-7' ) ); ?>)<br />
188 <input type="number" name="min" class="numeric oneline option" /></td>
189
190 <td><code>max</code> (<?php echo esc_html( __( 'optional', 'contact-form-7' ) ); ?>)<br />
191 <input type="number" name="max" class="numeric oneline option" /></td>
192 </tr>
193
194 <tr>
195 <td><code>step</code> (<?php echo esc_html( __( 'optional', 'contact-form-7' ) ); ?>)<br />
196 <input type="number" name="step" class="numeric oneline option" min="1" /></td>
197 </tr>
198
199 <tr>
200 <td><?php echo esc_html( __( 'Default value', 'contact-form-7' ) ); ?> (<?php echo esc_html( __( 'optional', 'contact-form-7' ) ); ?>)<br /><input type="text" name="values" class="oneline" /></td>
201
202 <td>
203 <br /><input type="checkbox" name="placeholder" class="option" />&nbsp;<?php echo esc_html( __( 'Use this text as placeholder?', 'contact-form-7' ) ); ?>
204 </td>
205 </tr>
206 </table>
207
208 <div class="tg-tag"><?php echo esc_html( __( "Copy this code and paste it into the form left.", 'contact-form-7' ) ); ?><br /><input type="text" name="<?php echo $type; ?>" class="tag wp-ui-text-highlight code" readonly="readonly" onfocus="this.select()" /></div>
209
210 <div class="tg-mail-tag"><?php echo esc_html( __( "And, put this code into the Mail fields below.", 'contact-form-7' ) ); ?><br /><input type="text" class="mail-tag wp-ui-text-highlight code" readonly="readonly" onfocus="this.select()" /></div>
211 </form>
212 </div>
213 <?php
214 }
215
216 ?>