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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 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
acceptance.php
173 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_id_option();
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 sanitize_html_class( $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 if ( isset( $result['reason'][$name] ) && $id = $tag->get_id_option() ) {
77 $result['idref'][$name] = $id;
78 }
79
80 return $result;
81 }
82
83
84 /* Acceptance filter */
85
86 add_filter( 'wpcf7_acceptance', 'wpcf7_acceptance_filter' );
87
88 function wpcf7_acceptance_filter( $accepted ) {
89 if ( ! $accepted )
90 return $accepted;
91
92 $fes = wpcf7_scan_shortcode( array( 'type' => 'acceptance' ) );
93
94 foreach ( $fes as $fe ) {
95 $name = $fe['name'];
96 $options = (array) $fe['options'];
97
98 if ( empty( $name ) )
99 continue;
100
101 $value = ( ! empty( $_POST[$name] ) ? 1 : 0 );
102
103 $invert = (bool) preg_grep( '%^invert$%', $options );
104
105 if ( $invert && $value || ! $invert && ! $value )
106 $accepted = false;
107 }
108
109 return $accepted;
110 }
111
112 add_filter( 'wpcf7_form_class_attr', 'wpcf7_acceptance_form_class_attr' );
113
114 function wpcf7_acceptance_form_class_attr( $class ) {
115 if ( wpcf7_acceptance_as_validation() )
116 return $class . ' wpcf7-acceptance-as-validation';
117
118 return $class;
119 }
120
121 function wpcf7_acceptance_as_validation() {
122 if ( ! $contact_form = wpcf7_get_current_contact_form() )
123 return false;
124
125 return $contact_form->is_true( 'acceptance_as_validation' );
126 }
127
128
129 /* Tag generator */
130
131 add_action( 'admin_init', 'wpcf7_add_tag_generator_acceptance', 35 );
132
133 function wpcf7_add_tag_generator_acceptance() {
134 if ( ! function_exists( 'wpcf7_add_tag_generator' ) )
135 return;
136
137 wpcf7_add_tag_generator( 'acceptance', __( 'Acceptance', 'contact-form-7' ),
138 'wpcf7-tg-pane-acceptance', 'wpcf7_tg_pane_acceptance' );
139 }
140
141 function wpcf7_tg_pane_acceptance( $contact_form ) {
142 ?>
143 <div id="wpcf7-tg-pane-acceptance" class="hidden">
144 <form action="">
145 <table>
146 <tr><td><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?><br /><input type="text" name="name" class="tg-name oneline" /></td><td></td></tr>
147 </table>
148
149 <table>
150 <tr>
151 <td><code>id</code> (<?php echo esc_html( __( 'optional', 'contact-form-7' ) ); ?>)<br />
152 <input type="text" name="id" class="idvalue oneline option" /></td>
153
154 <td><code>class</code> (<?php echo esc_html( __( 'optional', 'contact-form-7' ) ); ?>)<br />
155 <input type="text" name="class" class="classvalue oneline option" /></td>
156 </tr>
157
158 <tr>
159 <td colspan="2">
160 <br /><input type="checkbox" name="default:on" class="option" />&nbsp;<?php echo esc_html( __( "Make this checkbox checked by default?", 'contact-form-7' ) ); ?>
161 <br /><input type="checkbox" name="invert" class="option" />&nbsp;<?php echo esc_html( __( "Make this checkbox work inversely?", 'contact-form-7' ) ); ?>
162 <br /><span style="font-size: smaller;"><?php echo esc_html( __( "* That means visitor who accepts the term unchecks it.", 'contact-form-7' ) ); ?></span>
163 </td>
164 </tr>
165 </table>
166
167 <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>
168 </form>
169 </div>
170 <?php
171 }
172
173 ?>