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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 / acceptance.php
contact-form-7 / modules Last commit date
akismet 3 years ago constant-contact 3 years ago recaptcha 3 years ago sendinblue 3 years ago stripe 3 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 9 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
acceptance.php
307 lines
1 <?php
2 /**
3 ** A base module for [acceptance]
4 **/
5
6 /* form_tag handler */
7
8 add_action( 'wpcf7_init', 'wpcf7_add_form_tag_acceptance', 10, 0 );
9
10 function wpcf7_add_form_tag_acceptance() {
11 wpcf7_add_form_tag( 'acceptance',
12 'wpcf7_acceptance_form_tag_handler',
13 array(
14 'name-attr' => true,
15 )
16 );
17 }
18
19 function wpcf7_acceptance_form_tag_handler( $tag ) {
20 if ( empty( $tag->name ) ) {
21 return '';
22 }
23
24 $validation_error = wpcf7_get_validation_error( $tag->name );
25
26 $class = wpcf7_form_controls_class( $tag->type );
27
28 if ( $validation_error ) {
29 $class .= ' wpcf7-not-valid';
30 }
31
32 if ( $tag->has_option( 'invert' ) ) {
33 $class .= ' invert';
34 }
35
36 if ( $tag->has_option( 'optional' ) ) {
37 $class .= ' optional';
38 }
39
40 $atts = array(
41 'class' => trim( $class ),
42 );
43
44 $item_atts = array(
45 'type' => 'checkbox',
46 'name' => $tag->name,
47 'value' => '1',
48 'tabindex' => $tag->get_option( 'tabindex', 'signed_int', true ),
49 'checked' => $tag->has_option( 'default:on' ),
50 'class' => $tag->get_class_option() ? $tag->get_class_option() : null,
51 'id' => $tag->get_id_option(),
52 );
53
54 if ( $validation_error ) {
55 $item_atts['aria-invalid'] = 'true';
56 $item_atts['aria-describedby'] = wpcf7_get_validation_error_reference(
57 $tag->name
58 );
59 } else {
60 $item_atts['aria-invalid'] = 'false';
61 }
62
63 $item_atts = wpcf7_format_atts( $item_atts );
64
65 $content = empty( $tag->content )
66 ? (string) reset( $tag->values )
67 : $tag->content;
68
69 $content = trim( $content );
70
71 if ( $content ) {
72 if ( $tag->has_option( 'label_first' ) ) {
73 $html = sprintf(
74 '<span class="wpcf7-list-item-label">%2$s</span><input %1$s />',
75 $item_atts,
76 $content
77 );
78 } else {
79 $html = sprintf(
80 '<input %1$s /><span class="wpcf7-list-item-label">%2$s</span>',
81 $item_atts,
82 $content
83 );
84 }
85
86 $html = sprintf(
87 '<span class="wpcf7-list-item"><label>%s</label></span>',
88 $html
89 );
90
91 } else {
92 $html = sprintf(
93 '<span class="wpcf7-list-item"><input %1$s /></span>',
94 $item_atts
95 );
96 }
97
98 $html = sprintf(
99 '<span class="wpcf7-form-control-wrap" data-name="%1$s"><span %2$s>%3$s</span>%4$s</span>',
100 esc_attr( $tag->name ),
101 wpcf7_format_atts( $atts ),
102 $html,
103 $validation_error
104 );
105
106 return $html;
107 }
108
109
110 /* Validation filter */
111
112 add_filter( 'wpcf7_validate_acceptance',
113 'wpcf7_acceptance_validation_filter', 10, 2 );
114
115 function wpcf7_acceptance_validation_filter( $result, $tag ) {
116 if ( ! wpcf7_acceptance_as_validation() ) {
117 return $result;
118 }
119
120 if ( $tag->has_option( 'optional' ) ) {
121 return $result;
122 }
123
124 $name = $tag->name;
125 $value = ( ! empty( $_POST[$name] ) ? 1 : 0 );
126
127 $invert = $tag->has_option( 'invert' );
128
129 if ( $invert and $value
130 or ! $invert and ! $value ) {
131 $result->invalidate( $tag, wpcf7_get_message( 'accept_terms' ) );
132 }
133
134 return $result;
135 }
136
137
138 /* Acceptance filter */
139
140 add_filter( 'wpcf7_acceptance', 'wpcf7_acceptance_filter', 10, 2 );
141
142 function wpcf7_acceptance_filter( $accepted, $submission ) {
143 $tags = wpcf7_scan_form_tags( array( 'type' => 'acceptance' ) );
144
145 foreach ( $tags as $tag ) {
146 $name = $tag->name;
147
148 if ( empty( $name ) ) {
149 continue;
150 }
151
152 $value = ( ! empty( $_POST[$name] ) ? 1 : 0 );
153
154 $content = empty( $tag->content )
155 ? (string) reset( $tag->values )
156 : $tag->content;
157
158 $content = trim( $content );
159
160 if ( $value and $content ) {
161 $submission->add_consent( $name, $content );
162 }
163
164 if ( $tag->has_option( 'optional' ) ) {
165 continue;
166 }
167
168 $invert = $tag->has_option( 'invert' );
169
170 if ( $invert and $value
171 or ! $invert and ! $value ) {
172 $accepted = false;
173 }
174 }
175
176 return $accepted;
177 }
178
179 add_filter( 'wpcf7_form_class_attr',
180 'wpcf7_acceptance_form_class_attr', 10, 1 );
181
182 function wpcf7_acceptance_form_class_attr( $class_attr ) {
183 if ( wpcf7_acceptance_as_validation() ) {
184 return $class_attr . ' wpcf7-acceptance-as-validation';
185 }
186
187 return $class_attr;
188 }
189
190 function wpcf7_acceptance_as_validation() {
191 if ( ! $contact_form = wpcf7_get_current_contact_form() ) {
192 return false;
193 }
194
195 return $contact_form->is_true( 'acceptance_as_validation' );
196 }
197
198 add_filter( 'wpcf7_mail_tag_replaced_acceptance',
199 'wpcf7_acceptance_mail_tag', 10, 4 );
200
201 function wpcf7_acceptance_mail_tag( $replaced, $submitted, $html, $mail_tag ) {
202 $form_tag = $mail_tag->corresponding_form_tag();
203
204 if ( ! $form_tag ) {
205 return $replaced;
206 }
207
208 if ( ! empty( $submitted ) ) {
209 $replaced = __( 'Consented', 'contact-form-7' );
210 } else {
211 $replaced = __( 'Not consented', 'contact-form-7' );
212 }
213
214 $content = empty( $form_tag->content )
215 ? (string) reset( $form_tag->values )
216 : $form_tag->content;
217
218 if ( ! $html ) {
219 $content = wp_strip_all_tags( $content );
220 }
221
222 $content = trim( $content );
223
224 if ( $content ) {
225 $replaced = sprintf(
226 /* translators: 1: 'Consented' or 'Not consented', 2: conditions */
227 _x( '%1$s: %2$s', 'mail output for acceptance checkboxes',
228 'contact-form-7' ),
229 $replaced,
230 $content
231 );
232 }
233
234 return $replaced;
235 }
236
237
238 /* Tag generator */
239
240 add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_acceptance', 35, 0 );
241
242 function wpcf7_add_tag_generator_acceptance() {
243 $tag_generator = WPCF7_TagGenerator::get_instance();
244 $tag_generator->add( 'acceptance', __( 'acceptance', 'contact-form-7' ),
245 'wpcf7_tag_generator_acceptance' );
246 }
247
248 function wpcf7_tag_generator_acceptance( $contact_form, $args = '' ) {
249 $args = wp_parse_args( $args, array() );
250 $type = 'acceptance';
251
252 $description = __( "Generate a form-tag for an acceptance checkbox. For more details, see %s.", 'contact-form-7' );
253
254 $desc_link = wpcf7_link( __( 'https://contactform7.com/acceptance-checkbox/', 'contact-form-7' ), __( 'Acceptance checkbox', 'contact-form-7' ) );
255
256 ?>
257 <div class="control-box">
258 <fieldset>
259 <legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
260
261 <table class="form-table">
262 <tbody>
263 <tr>
264 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
265 <td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
266 </tr>
267
268 <tr>
269 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-content' ); ?>"><?php echo esc_html( __( 'Condition', 'contact-form-7' ) ); ?></label></th>
270 <td><input type="text" name="content" class="oneline large-text" id="<?php echo esc_attr( $args['content'] . '-content' ); ?>" /></td>
271 </tr>
272
273 <tr>
274 <th scope="row"><?php echo esc_html( __( 'Options', 'contact-form-7' ) ); ?></th>
275 <td>
276 <fieldset>
277 <legend class="screen-reader-text"><?php echo esc_html( __( 'Options', 'contact-form-7' ) ); ?></legend>
278 <label><input type="checkbox" name="optional" class="option" checked="checked" /> <?php echo esc_html( __( 'Make this checkbox optional', 'contact-form-7' ) ); ?></label>
279 </fieldset>
280 </td>
281 </tr>
282
283 <tr>
284 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
285 <td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
286 </tr>
287
288 <tr>
289 <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
290 <td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
291 </tr>
292
293 </tbody>
294 </table>
295 </fieldset>
296 </div>
297
298 <div class="insert-box">
299 <input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()" />
300
301 <div class="submitbox">
302 <input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
303 </div>
304 </div>
305 <?php
306 }
307