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