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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
acceptance.php 12 years ago akismet.php 13 years ago captcha.php 12 years ago checkbox.php 12 years ago date.php 12 years ago file.php 12 years ago flamingo.php 12 years ago jetpack.php 12 years ago number.php 12 years ago quiz.php 12 years ago response.php 15 years ago select.php 12 years ago special-mail-tags.php 13 years ago submit.php 12 years ago text.php 12 years ago textarea.php 12 years ago
acceptance.php
169 lines
1 <?php
2 /**
3 ** A base module for [acceptance]
4 **/
5
6 /* Shortcode handler */
7
8 add_action( 'wpcf7_init', 'wpcf7_add_shortcode_acceptance' );
9
10 function wpcf7_add_shortcode_acceptance() {
11 wpcf7_add_shortcode( 'acceptance',
12 'wpcf7_acceptance_shortcode_handler', true );
13 }
14
15 function wpcf7_acceptance_shortcode_handler( $tag ) {
16 $tag = new WPCF7_Shortcode( $tag );
17
18 if ( empty( $tag->name ) )
19 return '';
20
21 $validation_error = wpcf7_get_validation_error( $tag->name );
22
23 $class = wpcf7_form_controls_class( $tag->type );
24
25 if ( $validation_error )
26 $class .= ' wpcf7-not-valid';
27
28 if ( $tag->has_option( 'invert' ) )
29 $class .= ' wpcf7-invert';
30
31 $atts = array();
32
33 $atts['class'] = $tag->get_class_option( $class );
34 $atts['id'] = $tag->get_option( 'id', 'id', true );
35 $atts['tabindex'] = $tag->get_option( 'tabindex', 'int', true );
36
37 if ( $tag->has_option( 'default:on' ) )
38 $atts['checked'] = 'checked';
39
40 $atts['aria-invalid'] = $validation_error ? 'true' : 'false';
41
42 $atts['type'] = 'checkbox';
43 $atts['name'] = $tag->name;
44 $atts['value'] = '1';
45
46 $atts = wpcf7_format_atts( $atts );
47
48 $html = sprintf(
49 '<span class="wpcf7-form-control-wrap %1$s"><input %2$s />%3$s</span>',
50 $tag->name, $atts, $validation_error );
51
52 return $html;
53 }
54
55
56 /* Validation filter */
57
58 add_filter( 'wpcf7_validate_acceptance', 'wpcf7_acceptance_validation_filter', 10, 2 );
59
60 function wpcf7_acceptance_validation_filter( $result, $tag ) {
61 if ( ! wpcf7_acceptance_as_validation() )
62 return $result;
63
64 $tag = new WPCF7_Shortcode( $tag );
65
66 $name = $tag->name;
67 $value = ( ! empty( $_POST[$name] ) ? 1 : 0 );
68
69 $invert = $tag->has_option( 'invert' );
70
71 if ( $invert && $value || ! $invert && ! $value ) {
72 $result['valid'] = false;
73 $result['reason'][$name] = wpcf7_get_message( 'accept_terms' );
74 }
75
76 return $result;
77 }
78
79
80 /* Acceptance filter */
81
82 add_filter( 'wpcf7_acceptance', 'wpcf7_acceptance_filter' );
83
84 function wpcf7_acceptance_filter( $accepted ) {
85 if ( ! $accepted )
86 return $accepted;
87
88 $fes = wpcf7_scan_shortcode( array( 'type' => 'acceptance' ) );
89
90 foreach ( $fes as $fe ) {
91 $name = $fe['name'];
92 $options = (array) $fe['options'];
93
94 if ( empty( $name ) )
95 continue;
96
97 $value = ( ! empty( $_POST[$name] ) ? 1 : 0 );
98
99 $invert = (bool) preg_grep( '%^invert$%', $options );
100
101 if ( $invert && $value || ! $invert && ! $value )
102 $accepted = false;
103 }
104
105 return $accepted;
106 }
107
108 add_filter( 'wpcf7_form_class_attr', 'wpcf7_acceptance_form_class_attr' );
109
110 function wpcf7_acceptance_form_class_attr( $class ) {
111 if ( wpcf7_acceptance_as_validation() )
112 return $class . ' wpcf7-acceptance-as-validation';
113
114 return $class;
115 }
116
117 function wpcf7_acceptance_as_validation() {
118 if ( ! $contact_form = wpcf7_get_current_contact_form() )
119 return false;
120
121 return $contact_form->is_true( 'acceptance_as_validation' );
122 }
123
124
125 /* Tag generator */
126
127 add_action( 'admin_init', 'wpcf7_add_tag_generator_acceptance', 35 );
128
129 function wpcf7_add_tag_generator_acceptance() {
130 if ( ! function_exists( 'wpcf7_add_tag_generator' ) )
131 return;
132
133 wpcf7_add_tag_generator( 'acceptance', __( 'Acceptance', 'contact-form-7' ),
134 'wpcf7-tg-pane-acceptance', 'wpcf7_tg_pane_acceptance' );
135 }
136
137 function wpcf7_tg_pane_acceptance( &$contact_form ) {
138 ?>
139 <div id="wpcf7-tg-pane-acceptance" class="hidden">
140 <form action="">
141 <table>
142 <tr><td><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?><br /><input type="text" name="name" class="tg-name oneline" /></td><td></td></tr>
143 </table>
144
145 <table>
146 <tr>
147 <td><code>id</code> (<?php echo esc_html( __( 'optional', 'contact-form-7' ) ); ?>)<br />
148 <input type="text" name="id" class="idvalue oneline option" /></td>
149
150 <td><code>class</code> (<?php echo esc_html( __( 'optional', 'contact-form-7' ) ); ?>)<br />
151 <input type="text" name="class" class="classvalue oneline option" /></td>
152 </tr>
153
154 <tr>
155 <td colspan="2">
156 <br /><input type="checkbox" name="default:on" class="option" />&nbsp;<?php echo esc_html( __( "Make this checkbox checked by default?", 'contact-form-7' ) ); ?>
157 <br /><input type="checkbox" name="invert" class="option" />&nbsp;<?php echo esc_html( __( "Make this checkbox work inversely?", 'contact-form-7' ) ); ?>
158 <br /><span style="font-size: smaller;"><?php echo esc_html( __( "* That means visitor who accepts the term unchecks it.", 'contact-form-7' ) ); ?></span>
159 </td>
160 </tr>
161 </table>
162
163 <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="acceptance" class="tag wp-ui-text-highlight code" readonly="readonly" onfocus="this.select()" /></div>
164 </form>
165 </div>
166 <?php
167 }
168
169 ?>