Conditional Fields for Contact Form 7 - Version 1.2.3

Version Description

  • Make plugin compatible with CF7 Multi Step by NinjaTeam https://wordpress.org/plugins/cf7-multi-step/
  • Improve compatibility with Signature Addon some more.
Download this release

Release Info

Developer Jules Colle
Plugin Icon 128x128 Conditional Fields for Contact Form 7
Version 1.2.3
Comparing to
See all releases

Code changes from version 1.2.2 to 1.2.3

Files changed (4) hide show
  1. cf7cf.php +10 -3
  2. contact-form-7-conditional-fields.php +2 -2
  3. js/scripts.js +40 -28
  4. readme.txt +5 -1
cf7cf.php CHANGED
@@ -16,15 +16,17 @@ class ContactForm7ConditionalFields {
16
  add_action('load-contact_page_wpcf7-new', array(__CLASS__, 'tag_generator'));
17
  add_action('load-toplevel_page_wpcf7', array(__CLASS__, 'tag_generator'));
18
 
19
- // compatibility with CF7 multi-step forms
20
  add_filter( 'wpcf7_posted_data', array($this,'cf7msm_merge_post_with_cookie'), 8, 1 );
21
 
 
 
 
 
22
  add_filter( 'wpcf7_posted_data', array($this, 'remove_hidden_post_data') );
23
  add_filter( 'wpcf7_mail_components', array($this, 'hide_hidden_mail_fields') );
24
  add_filter('wpcf7_additional_mail', array($this, 'hide_hidden_mail_fields_additional_mail'), 10, 2);
25
 
26
- //apply_filters( 'wpcf7_additional_mail',$additional_mail, $contact_form )
27
-
28
  add_filter( 'wpcf7_validate', array($this, 'skip_validation_for_hidden_fields'), 2, 2 );
29
 
30
  register_activation_hook(__FILE__, array($this, 'activate'));
@@ -198,6 +200,11 @@ class ContactForm7ConditionalFields {
198
  return $posted_data;
199
  }
200
 
 
 
 
 
 
201
 
202
  /**
203
  * Finds the currently submitted form and set the hidden_fields variables accoringly
16
  add_action('load-contact_page_wpcf7-new', array(__CLASS__, 'tag_generator'));
17
  add_action('load-toplevel_page_wpcf7', array(__CLASS__, 'tag_generator'));
18
 
19
+ // compatibility with CF7 multi-step forms by Webhead LLC.
20
  add_filter( 'wpcf7_posted_data', array($this,'cf7msm_merge_post_with_cookie'), 8, 1 );
21
 
22
+ // compatibility with CF7 Multi Step by NinjaTeam https://wordpress.org/plugins/cf7-multi-step/
23
+ add_action('wp_ajax_cf7mls_validation', array($this,'cf7mls_validation_callback'),9);
24
+ add_action('wp_ajax_nopriv_cf7mls_validation', array($this,'cf7mls_validation_callback'),9);
25
+
26
  add_filter( 'wpcf7_posted_data', array($this, 'remove_hidden_post_data') );
27
  add_filter( 'wpcf7_mail_components', array($this, 'hide_hidden_mail_fields') );
28
  add_filter('wpcf7_additional_mail', array($this, 'hide_hidden_mail_fields_additional_mail'), 10, 2);
29
 
 
 
30
  add_filter( 'wpcf7_validate', array($this, 'skip_validation_for_hidden_fields'), 2, 2 );
31
 
32
  register_activation_hook(__FILE__, array($this, 'activate'));
200
  return $posted_data;
201
  }
202
 
203
+ // compatibility with CF7 Multi Step by NinjaTeam https://wordpress.org/plugins/cf7-multi-step/
204
+ function cf7mls_validation_callback() {
205
+ $this->set_hidden_fields_arrays($_POST);
206
+ }
207
+
208
 
209
  /**
210
  * Finds the currently submitted form and set the hidden_fields variables accoringly
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: 1.2.2
8
  Author URI: http://bdwm.be/
9
  */
10
 
@@ -24,7 +24,7 @@ Author URI: http://bdwm.be/
24
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
  */
26
 
27
- if (!defined('WPCF7CF_VERSION')) define( 'WPCF7CF_VERSION', '1.2.2' );
28
  if (!defined('WPCF7CF_REQUIRED_WP_VERSION')) define( 'WPCF7CF_REQUIRED_WP_VERSION', '4.1' );
29
  if (!defined('WPCF7CF_PLUGIN')) define( 'WPCF7CF_PLUGIN', __FILE__ );
30
  if (!defined('WPCF7CF_PLUGIN_BASENAME')) define( 'WPCF7CF_PLUGIN_BASENAME', plugin_basename( WPCF7CF_PLUGIN ) );
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: 1.2.3
8
  Author URI: http://bdwm.be/
9
  */
10
 
24
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
  */
26
 
27
+ if (!defined('WPCF7CF_VERSION')) define( 'WPCF7CF_VERSION', '1.2.3' );
28
  if (!defined('WPCF7CF_REQUIRED_WP_VERSION')) define( 'WPCF7CF_REQUIRED_WP_VERSION', '4.1' );
29
  if (!defined('WPCF7CF_PLUGIN')) define( 'WPCF7CF_PLUGIN', __FILE__ );
30
  if (!defined('WPCF7CF_PLUGIN_BASENAME')) define( 'WPCF7CF_PLUGIN_BASENAME', plugin_basename( WPCF7CF_PLUGIN ) );
js/scripts.js CHANGED
@@ -18,8 +18,8 @@ var cf7signature_resized = 0; // for compatibility with contact-form-7-signature
18
 
19
  //for compatibility with contact-form-7-signature-addon
20
  if (cf7signature_resized == 0 && typeof signatures !== 'undefined' && signatures.constructor === Array && signatures.length > 0 ) {
21
- if (signatures[0].canvas.width == 0) {
22
- for (var i = 0; i < signatures.length; i++) {
23
 
24
  jQuery(".wpcf7-form-control-signature-body>canvas").eq(i).attr('width', jQuery(".wpcf7-form-control-signature-wrap").width());
25
  jQuery(".wpcf7-form-control-signature-body>canvas").eq(i).attr('height', jQuery(".wpcf7-form-control-signature-wrap").height());
@@ -163,37 +163,49 @@ var cf7signature_resized = 0; // for compatibility with contact-form-7-signature
163
 
164
  // before the form values are serialized to submit via ajax, we quickly add all invisible fields in the hidden
165
  // _wpcf7cf_hidden_group_fields field, so the PHP code knows which fields were inside hidden groups.
166
-
167
  $('form.wpcf7-form').on('form-pre-serialize', function(form,options,veto) {
168
  $form = $(form.target);
 
 
 
 
 
 
 
 
 
 
 
 
169
 
170
- $hidden_group_fields = $form.find('[name="_wpcf7cf_hidden_group_fields"]');
171
- $hidden_groups = $form.find('[name="_wpcf7cf_hidden_groups"]');
172
- $visible_groups = $form.find('[name="_wpcf7cf_visible_groups"]');
173
-
174
- var hidden_fields = [];
175
- var hidden_groups = [];
176
- var visible_groups = [];
177
-
178
- $form.find('[data-class="wpcf7cf_group"]').each(function () {
179
- var $this = $(this);
180
- if ($this.hasClass('wpcf7cf-hidden')) {
181
- hidden_groups.push($this.attr('id'));
182
- $this.find('input,select,textarea').each(function () {
183
- hidden_fields.push($(this).attr('name'));
184
- });
185
- } else {
186
- visible_groups.push($this.attr('id'));
187
- }
188
- });
 
 
189
 
190
- $hidden_group_fields.val(JSON.stringify(hidden_fields));
191
- $hidden_groups.val(JSON.stringify(hidden_groups));
192
- $visible_groups.val(JSON.stringify(visible_groups));
193
 
194
- return true;
195
- });
196
- });
197
 
198
  //reset the form completely
199
  $( document ).ajaxComplete(function(e,xhr) {
18
 
19
  //for compatibility with contact-form-7-signature-addon
20
  if (cf7signature_resized == 0 && typeof signatures !== 'undefined' && signatures.constructor === Array && signatures.length > 0 ) {
21
+ for (var i = 0; i < signatures.length; i++) {
22
+ if (signatures[i].canvas.width == 0) {
23
 
24
  jQuery(".wpcf7-form-control-signature-body>canvas").eq(i).attr('width', jQuery(".wpcf7-form-control-signature-wrap").width());
25
  jQuery(".wpcf7-form-control-signature-body>canvas").eq(i).attr('height', jQuery(".wpcf7-form-control-signature-wrap").height());
163
 
164
  // before the form values are serialized to submit via ajax, we quickly add all invisible fields in the hidden
165
  // _wpcf7cf_hidden_group_fields field, so the PHP code knows which fields were inside hidden groups.
 
166
  $('form.wpcf7-form').on('form-pre-serialize', function(form,options,veto) {
167
  $form = $(form.target);
168
+ wpcf7cf_update_hidden_fields($form);
169
+ });
170
+ // Actually we need to add the hidden fields values after every change in case the form values
171
+ // get submitted trough Ajax by another plugin (Example multi-step form plugins)
172
+ $('form.wpcf7-form :input').change(function() {
173
+ wpcf7cf_update_hidden_fields($(this).closest('form'));
174
+ });
175
+ // And in case a form gets submitted without any input:
176
+ $('form.wpcf7-form').each(function(){
177
+ wpcf7cf_update_hidden_fields($(this));
178
+ });
179
+ });
180
 
181
+ function wpcf7cf_update_hidden_fields($form) {
182
+
183
+ $hidden_group_fields = $form.find('[name="_wpcf7cf_hidden_group_fields"]');
184
+ $hidden_groups = $form.find('[name="_wpcf7cf_hidden_groups"]');
185
+ $visible_groups = $form.find('[name="_wpcf7cf_visible_groups"]');
186
+
187
+ var hidden_fields = [];
188
+ var hidden_groups = [];
189
+ var visible_groups = [];
190
+
191
+ $form.find('[data-class="wpcf7cf_group"]').each(function () {
192
+ var $this = $(this);
193
+ if ($this.hasClass('wpcf7cf-hidden')) {
194
+ hidden_groups.push($this.attr('id'));
195
+ $this.find('input,select,textarea').each(function () {
196
+ hidden_fields.push($(this).attr('name'));
197
+ });
198
+ } else {
199
+ visible_groups.push($this.attr('id'));
200
+ }
201
+ });
202
 
203
+ $hidden_group_fields.val(JSON.stringify(hidden_fields));
204
+ $hidden_groups.val(JSON.stringify(hidden_groups));
205
+ $visible_groups.val(JSON.stringify(visible_groups));
206
 
207
+ return true;
208
+ }
 
209
 
210
  //reset the form completely
211
  $( document ).ajaxComplete(function(e,xhr) {
readme.txt CHANGED
@@ -6,7 +6,7 @@ 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.2
9
- Stable tag: 1.2.2
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
@@ -83,6 +83,10 @@ I will assume that you successfully installed both plugins, that you were able t
83
 
84
  == Changelog ==
85
 
 
 
 
 
86
  = 1.2.2 =
87
  * Fix critical bug that was present in version 1.2 and 1.2.1
88
 
6
  Tags: wordpress, contact form 7, forms, conditional fields
7
  Requires at least: 4.1
8
  Tested up to: 4.7.2
9
+ Stable tag: 1.2.3
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
83
 
84
  == Changelog ==
85
 
86
+ = 1.2.3 =
87
+ * Make plugin compatible with CF7 Multi Step by NinjaTeam https://wordpress.org/plugins/cf7-multi-step/
88
+ * Improve compatibility with Signature Addon some more.
89
+
90
  = 1.2.2 =
91
  * Fix critical bug that was present in version 1.2 and 1.2.1
92