Version Description
- Fixed bug that destroyed the conditional fields in email functionality
Download this release
Release Info
Developer | Jules Colle |
Plugin | Conditional Fields for Contact Form 7 |
Version | 0.2.4 |
Comparing to | |
See all releases |
Code changes from version 0.2.3 to 0.2.4
- contact-form-7-conditional-fields.php +15 -19
- js/scripts.js +14 -0
- readme.txt +6 -3
contact-form-7-conditional-fields.php
CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Contact Form 7 Conditional Fields
|
|
4 |
Plugin URI: http://bdwm.be/
|
5 |
Description: Adds support for conditional fields to Contact Form 7. This plugin depends on Contact Form 7.
|
6 |
Author: Jules Colle
|
7 |
-
Version: 0.2.
|
8 |
Author URI: http://bdwm.be/
|
9 |
*/
|
10 |
|
@@ -26,7 +26,7 @@ Author URI: http://bdwm.be/
|
|
26 |
?>
|
27 |
<?php
|
28 |
|
29 |
-
define( 'WPCF7CF_VERSION', '0.2.
|
30 |
define( 'WPCF7CF_REQUIRED_WP_VERSION', '4.1' );
|
31 |
define( 'WPCF7CF_PLUGIN', __FILE__ );
|
32 |
define( 'WPCF7CF_PLUGIN_BASENAME', plugin_basename( WPCF7CF_PLUGIN ) );
|
@@ -65,6 +65,8 @@ class ContactForm7ConditionalFields {
|
|
65 |
add_filter( 'wpcf7_posted_data', array($this, 'remove_hidden_post_data') );
|
66 |
add_filter( 'wpcf7_mail_components', array($this, 'hide_hidden_mail_fields') );
|
67 |
|
|
|
|
|
68 |
register_activation_hook(__FILE__, array($this, 'activate'));
|
69 |
|
70 |
if (is_admin()) {
|
@@ -160,17 +162,15 @@ class ContactForm7ConditionalFields {
|
|
160 |
* @return mixed
|
161 |
*/
|
162 |
function skip_validation_for_hidden_fields($result, $tags) {
|
163 |
-
|
164 |
-
$hidden_fields
|
165 |
|
166 |
$return_result = new WPCF7_Validation();
|
167 |
|
168 |
$invalid_fields = $result->get_invalid_fields();
|
169 |
|
170 |
-
$invalid_shown_fields = array();
|
171 |
-
|
172 |
foreach ($invalid_fields as $invalid_field_key => $invalid_field_data) {
|
173 |
-
if (!in_array($invalid_field_key, $hidden_fields)) {
|
174 |
// the invalid field is not a hidden field, so we'll add it to the final validation result
|
175 |
$return_result->invalidate($invalid_field_key, $invalid_field_data['reason']);
|
176 |
}
|
@@ -188,34 +188,30 @@ class ContactForm7ConditionalFields {
|
|
188 |
* @return mixed
|
189 |
*/
|
190 |
function remove_hidden_post_data($posted_data) {
|
191 |
-
$
|
192 |
|
193 |
-
foreach( $hidden_fields as $name => $value ) {
|
194 |
unset( $posted_data[$name] );
|
195 |
}
|
|
|
196 |
return $posted_data;
|
197 |
}
|
198 |
|
199 |
|
200 |
/**
|
201 |
-
* Finds the currently submitted form and
|
202 |
*
|
203 |
* @param bool|array $posted_data
|
204 |
-
* @return mixed
|
205 |
*/
|
206 |
-
function
|
207 |
-
|
208 |
-
if (count( $this->hidden_fields ) > 0) return $this->hidden_fields;
|
209 |
|
210 |
if (!$posted_data) {
|
211 |
$posted_data = WPCF7_Submission::get_instance()->get_posted_data();
|
212 |
}
|
213 |
|
214 |
$this->hidden_fields = json_decode(stripslashes($posted_data['_wpcf7cf_hidden_group_fields']));
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
return $this->hidden_fields;
|
219 |
}
|
220 |
|
221 |
function hide_hidden_mail_fields( $components ) {
|
@@ -319,5 +315,5 @@ function wpcf7cf_enqueue_scripts(WPCF7_ContactForm $cf7form) {
|
|
319 |
add_action('wpcf7_form_hidden_fields', 'wpcf7cf_form_hidden_fields',10,1);
|
320 |
|
321 |
function wpcf7cf_form_hidden_fields($hidden_fields) {
|
322 |
-
return array('_wpcf7cf_hidden_group_fields' => '');
|
323 |
}
|
4 |
Plugin URI: http://bdwm.be/
|
5 |
Description: Adds support for conditional fields to Contact Form 7. This plugin depends on Contact Form 7.
|
6 |
Author: Jules Colle
|
7 |
+
Version: 0.2.4
|
8 |
Author URI: http://bdwm.be/
|
9 |
*/
|
10 |
|
26 |
?>
|
27 |
<?php
|
28 |
|
29 |
+
define( 'WPCF7CF_VERSION', '0.2.4' );
|
30 |
define( 'WPCF7CF_REQUIRED_WP_VERSION', '4.1' );
|
31 |
define( 'WPCF7CF_PLUGIN', __FILE__ );
|
32 |
define( 'WPCF7CF_PLUGIN_BASENAME', plugin_basename( WPCF7CF_PLUGIN ) );
|
65 |
add_filter( 'wpcf7_posted_data', array($this, 'remove_hidden_post_data') );
|
66 |
add_filter( 'wpcf7_mail_components', array($this, 'hide_hidden_mail_fields') );
|
67 |
|
68 |
+
add_filter( 'wpcf7_validate', array($this, 'skip_validation_for_hidden_fields'), 2, 2 );
|
69 |
+
|
70 |
register_activation_hook(__FILE__, array($this, 'activate'));
|
71 |
|
72 |
if (is_admin()) {
|
162 |
* @return mixed
|
163 |
*/
|
164 |
function skip_validation_for_hidden_fields($result, $tags) {
|
165 |
+
|
166 |
+
if (count($this->hidden_fields) == 0) return $result;
|
167 |
|
168 |
$return_result = new WPCF7_Validation();
|
169 |
|
170 |
$invalid_fields = $result->get_invalid_fields();
|
171 |
|
|
|
|
|
172 |
foreach ($invalid_fields as $invalid_field_key => $invalid_field_data) {
|
173 |
+
if (!in_array($invalid_field_key, $this->hidden_fields)) {
|
174 |
// the invalid field is not a hidden field, so we'll add it to the final validation result
|
175 |
$return_result->invalidate($invalid_field_key, $invalid_field_data['reason']);
|
176 |
}
|
188 |
* @return mixed
|
189 |
*/
|
190 |
function remove_hidden_post_data($posted_data) {
|
191 |
+
$this->set_hidden_fields_arrays($posted_data);
|
192 |
|
193 |
+
foreach( $this->hidden_fields as $name => $value ) {
|
194 |
unset( $posted_data[$name] );
|
195 |
}
|
196 |
+
|
197 |
return $posted_data;
|
198 |
}
|
199 |
|
200 |
|
201 |
/**
|
202 |
+
* Finds the currently submitted form and set the hidden_fields variables accoringly
|
203 |
*
|
204 |
* @param bool|array $posted_data
|
|
|
205 |
*/
|
206 |
+
function set_hidden_fields_arrays($posted_data = false) {
|
|
|
|
|
207 |
|
208 |
if (!$posted_data) {
|
209 |
$posted_data = WPCF7_Submission::get_instance()->get_posted_data();
|
210 |
}
|
211 |
|
212 |
$this->hidden_fields = json_decode(stripslashes($posted_data['_wpcf7cf_hidden_group_fields']));
|
213 |
+
$this->hidden_groups = json_decode(stripslashes($posted_data['_wpcf7cf_hidden_groups']));
|
214 |
+
$this->visible_groups = json_decode(stripslashes($posted_data['_wpcf7cf_visible_groups']));
|
|
|
|
|
215 |
}
|
216 |
|
217 |
function hide_hidden_mail_fields( $components ) {
|
315 |
add_action('wpcf7_form_hidden_fields', 'wpcf7cf_form_hidden_fields',10,1);
|
316 |
|
317 |
function wpcf7cf_form_hidden_fields($hidden_fields) {
|
318 |
+
return array('_wpcf7cf_hidden_group_fields' => '', '_wpcf7cf_hidden_groups' => '', '_wpcf7cf_visible_groups' => '');
|
319 |
}
|
js/scripts.js
CHANGED
@@ -109,14 +109,28 @@ var cf7signature_resized = 0; // for compatibility with contact-form-7-signature
|
|
109 |
$form = $(form.target);
|
110 |
|
111 |
$hidden_group_fields = $form.find('[name="_wpcf7cf_hidden_group_fields"]');
|
|
|
|
|
112 |
|
113 |
var hidden_fields = [];
|
|
|
|
|
114 |
|
115 |
$form.find('input:hidden,select:hidden,textarea:hidden').each(function () {
|
116 |
hidden_fields.push($(this).attr('name'));
|
117 |
});
|
118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
$($hidden_group_fields).val(JSON.stringify(hidden_fields));
|
|
|
|
|
120 |
|
121 |
return true;
|
122 |
});
|
109 |
$form = $(form.target);
|
110 |
|
111 |
$hidden_group_fields = $form.find('[name="_wpcf7cf_hidden_group_fields"]');
|
112 |
+
$hidden_groups = $form.find('[name="_wpcf7cf_hidden_groups"]');
|
113 |
+
$visible_groups = $form.find('[name="_wpcf7cf_visible_groups"]');
|
114 |
|
115 |
var hidden_fields = [];
|
116 |
+
var hidden_groups = [];
|
117 |
+
var visible_groups = [];
|
118 |
|
119 |
$form.find('input:hidden,select:hidden,textarea:hidden').each(function () {
|
120 |
hidden_fields.push($(this).attr('name'));
|
121 |
});
|
122 |
|
123 |
+
$form.find('[data-class="wpcf7cf_group"]:hidden').each(function () {
|
124 |
+
hidden_groups.push($(this).attr('id'));
|
125 |
+
});
|
126 |
+
|
127 |
+
$form.find('[data-class="wpcf7cf_group"]:visible').each(function () {
|
128 |
+
visible_groups.push($(this).attr('id'));
|
129 |
+
});
|
130 |
+
|
131 |
$($hidden_group_fields).val(JSON.stringify(hidden_fields));
|
132 |
+
$($hidden_groups).val(JSON.stringify(hidden_groups));
|
133 |
+
$($visible_groups).val(JSON.stringify(visible_groups));
|
134 |
|
135 |
return true;
|
136 |
});
|
readme.txt
CHANGED
@@ -4,9 +4,9 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=j_col
|
|
4 |
Author: Jules Colle
|
5 |
Website: http://bdwm.be
|
6 |
Tags: wordpress, contact form 7, forms, conditional fields
|
7 |
-
Requires at least:
|
8 |
-
Tested up to: 4.
|
9 |
-
Stable tag: 0.2.
|
10 |
License: GPLv2 or later
|
11 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
12 |
|
@@ -47,6 +47,9 @@ Because no questions have been asked frequently about this plugin.
|
|
47 |
|
48 |
== Changelog ==
|
49 |
|
|
|
|
|
|
|
50 |
= 0.2.3 =
|
51 |
* Added support for conditional fields in the other email fields (subject, sender, recipient, additional_headers). Thanks @stevish!
|
52 |
* WP 4.7 broke the required conditional fields inside hidden groups, implemented in version 0.2. Thanks again to @stevish for pointing this out.
|
4 |
Author: Jules Colle
|
5 |
Website: http://bdwm.be
|
6 |
Tags: wordpress, contact form 7, forms, conditional fields
|
7 |
+
Requires at least: 4.1
|
8 |
+
Tested up to: 4.7
|
9 |
+
Stable tag: 0.2.4
|
10 |
License: GPLv2 or later
|
11 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
12 |
|
47 |
|
48 |
== Changelog ==
|
49 |
|
50 |
+
= 0.2.4 =
|
51 |
+
* Fixed bug that destroyed the conditional fields in email functionality
|
52 |
+
|
53 |
= 0.2.3 =
|
54 |
* Added support for conditional fields in the other email fields (subject, sender, recipient, additional_headers). Thanks @stevish!
|
55 |
* WP 4.7 broke the required conditional fields inside hidden groups, implemented in version 0.2. Thanks again to @stevish for pointing this out.
|