Conditional Fields for Contact Form 7 - Version 0.2.5

Version Description

  • Changed deprecated function wpcf7_add_shortcode to wpcf7_add_form_tag as it was causing errors in debug mode. (https://wordpress.org/support/topic/wpcf7_add_shortcode-deprecated-notice-2/)
  • Removed the hide option and fixed the not-equals option for single checkboxes
Download this release

Release Info

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

Code changes from version 0.2.4 to 0.2.5

admin.php CHANGED
@@ -55,15 +55,6 @@ function all_operator_options($selected = 'equals') {
55
  }
56
  }
57
 
58
- function all_display_options($selected = 'show') {
59
- $all_options = array('show', 'hide');
60
- foreach($all_options as $option) {
61
- ?>
62
- <option value="<?php echo $option ?>" <?php echo $selected == $option?'selected':'' ?>><?php echo $option ?></option>
63
- <?php
64
- }
65
- }
66
-
67
  function wpcf7cf_editor_panel_conditional($form) {
68
 
69
  $form_id = $_GET['post'];
@@ -81,8 +72,7 @@ function wpcf7cf_editor_panel_conditional($form) {
81
  <select name="wpcf7cf_options[{id}][if_field]" class="if-field-select"><?php all_field_options($form); ?></select>
82
  <select name="wpcf7cf_options[{id}][operator]" class="operator"><?php all_operator_options(); ?></select>
83
  <input name="wpcf7cf_options[{id}][if_value]" class="if-value" type="text" placeholder="value">
84
- then
85
- <select name="wpcf7cf_options[{id}][then_visibility]" class="then-visibility"><?php all_display_options() ?></select>
86
  <select name="wpcf7cf_options[{id}][then_field]" class="then-field-select"><?php all_group_options($form); ?></select>
87
  </div>
88
  <a id="wpcf7cf-delete-button" class="delete-button" title="delete rule" href="#"><span class="dashicons dashicons-dismiss"></span> Remove rule</a>
@@ -98,8 +88,7 @@ function wpcf7cf_editor_panel_conditional($form) {
98
  <select name="wpcf7cf_options[<?php echo $i ?>][if_field]" class="if-field-select"><?php all_field_options($form, $entry['if_field']); ?></select>
99
  <select name="wpcf7cf_options[<?php echo $i ?>][operator]" class="operator"><?php all_operator_options($entry['operator']) ?></select>
100
  <input name="wpcf7cf_options[<?php echo $i ?>][if_value]" class="if-value" type="text" placeholder="value" value="<?php echo $entry['if_value'] ?>">
101
- then
102
- <select name="wpcf7cf_options[<?php echo $i ?>][then_visibility]" class="then-visibility"><?php all_display_options($entry['then_visibility']) ?></select>
103
  <select name="wpcf7cf_options[<?php echo $i ?>][then_field]" class="then-field-select"><?php all_group_options($form, $entry['then_field']); ?></select>
104
  <a style="display: inline-block;" href="#" title="delete rule" class="delete-button"><span class="dashicons dashicons-dismiss"></span> Remove rule</a>
105
  </div>
@@ -168,8 +157,7 @@ function wpcf7cf_editor_panel_conditional($form) {
168
  var $entry = $(this);
169
  var line = 'if [' + $entry.find('.if-field-select').val() + ']'
170
  + ' ' + $entry.find('.operator').val()
171
- + ' "' + $entry.find('.if-value').val() + '" then '
172
- + $entry.find('.then-visibility').val()
173
  + ' [' + $entry.find('.then-field-select').val() + ']';
174
  $('#wpcf7cf-settings-text').val($('#wpcf7cf-settings-text').val() + line + "\n" ).select();
175
  });
55
  }
56
  }
57
 
 
 
 
 
 
 
 
 
 
58
  function wpcf7cf_editor_panel_conditional($form) {
59
 
60
  $form_id = $_GET['post'];
72
  <select name="wpcf7cf_options[{id}][if_field]" class="if-field-select"><?php all_field_options($form); ?></select>
73
  <select name="wpcf7cf_options[{id}][operator]" class="operator"><?php all_operator_options(); ?></select>
74
  <input name="wpcf7cf_options[{id}][if_value]" class="if-value" type="text" placeholder="value">
75
+ then show
 
76
  <select name="wpcf7cf_options[{id}][then_field]" class="then-field-select"><?php all_group_options($form); ?></select>
77
  </div>
78
  <a id="wpcf7cf-delete-button" class="delete-button" title="delete rule" href="#"><span class="dashicons dashicons-dismiss"></span> Remove rule</a>
88
  <select name="wpcf7cf_options[<?php echo $i ?>][if_field]" class="if-field-select"><?php all_field_options($form, $entry['if_field']); ?></select>
89
  <select name="wpcf7cf_options[<?php echo $i ?>][operator]" class="operator"><?php all_operator_options($entry['operator']) ?></select>
90
  <input name="wpcf7cf_options[<?php echo $i ?>][if_value]" class="if-value" type="text" placeholder="value" value="<?php echo $entry['if_value'] ?>">
91
+ then show
 
92
  <select name="wpcf7cf_options[<?php echo $i ?>][then_field]" class="then-field-select"><?php all_group_options($form, $entry['then_field']); ?></select>
93
  <a style="display: inline-block;" href="#" title="delete rule" class="delete-button"><span class="dashicons dashicons-dismiss"></span> Remove rule</a>
94
  </div>
157
  var $entry = $(this);
158
  var line = 'if [' + $entry.find('.if-field-select').val() + ']'
159
  + ' ' + $entry.find('.operator').val()
160
+ + ' "' + $entry.find('.if-value').val() + '" then show'
 
161
  + ' [' + $entry.find('.then-field-select').val() + ']';
162
  $('#wpcf7cf-settings-text').val($('#wpcf7cf-settings-text').val() + line + "\n" ).select();
163
  });
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.4
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.4' );
30
  define( 'WPCF7CF_REQUIRED_WP_VERSION', '4.1' );
31
  define( 'WPCF7CF_PLUGIN', __FILE__ );
32
  define( 'WPCF7CF_PLUGIN_BASENAME', plugin_basename( WPCF7CF_PLUGIN ) );
@@ -87,8 +87,9 @@ class ContactForm7ConditionalFields {
87
  }
88
 
89
  public static function add_shortcodes() {
90
- wpcf7_add_shortcode('group', array(__CLASS__, 'shortcode_handler'), true);
91
  //add_shortcode( 'group', array(__CLASS__, 'group_shortcode_handler') );
 
92
  }
93
 
94
  function group_shortcode_handler( $atts, $content = "" ) {
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.5
8
  Author URI: http://bdwm.be/
9
  */
10
 
26
  ?>
27
  <?php
28
 
29
+ define( 'WPCF7CF_VERSION', '0.2.5' );
30
  define( 'WPCF7CF_REQUIRED_WP_VERSION', '4.1' );
31
  define( 'WPCF7CF_PLUGIN', __FILE__ );
32
  define( 'WPCF7CF_PLUGIN_BASENAME', plugin_basename( WPCF7CF_PLUGIN ) );
87
  }
88
 
89
  public static function add_shortcodes() {
90
+ //wpcf7_add_shortcode('group', array(__CLASS__, 'shortcode_handler'), true);
91
  //add_shortcode( 'group', array(__CLASS__, 'group_shortcode_handler') );
92
+ wpcf7_add_form_tag('group', array(__CLASS__, 'shortcode_handler'), true);
93
  }
94
 
95
  function group_shortcode_handler( $atts, $content = "" ) {
js/scripts.js CHANGED
@@ -29,24 +29,27 @@ var cf7signature_resized = 0; // for compatibility with contact-form-7-signature
29
  }
30
  }
31
 
32
-
33
  $("#"+unit_tag+" [data-class='wpcf7cf_group']").hide();
34
  for (var i=0; i < wpcf7cf_conditions.length; i++) {
35
 
36
  var condition = wpcf7cf_conditions[i];
37
- if (condition.then_visibility == 'hide') continue;
38
 
39
- $field = $('#'+unit_tag+' [name='+condition.if_field+']').length ? $('#'+unit_tag+' [name='+condition.if_field+']') : $('#'+unit_tag+' [name='+condition.if_field+'\\[\\]]');
40
 
41
  if ($field.length == 1) {
42
 
 
 
43
  // single field (tested with text field, single checkbox, select with single value (dropdown), select with multiple values)
44
 
45
  if ($field.is('select')) {
 
46
  var show = false;
 
47
  if(condition.operator == 'not equals') {
48
  show = true;
49
  }
 
50
  $field.find('option:selected').each(function () {
51
  var $option = $(this);
52
  if (condition.operator == 'equals' && $option.val() == condition.if_value) {
@@ -55,6 +58,7 @@ var cf7signature_resized = 0; // for compatibility with contact-form-7-signature
55
  show = false;
56
  }
57
  });
 
58
  if(show == true) {
59
  $('#' + unit_tag + ' #' + condition.then_field).show();
60
  }
@@ -62,8 +66,17 @@ var cf7signature_resized = 0; // for compatibility with contact-form-7-signature
62
  continue;
63
  }
64
 
65
- if (condition.operator == 'equals' && $field.val() == condition.if_value || condition.operator == 'not equals' && $field.val() != condition.if_value) {
66
- if ($field.attr('type') == 'checkbox' && !$field.attr('checked')) continue;
 
 
 
 
 
 
 
 
 
67
  $('#'+unit_tag+' #'+condition.then_field).show();
68
  }
69
 
29
  }
30
  }
31
 
 
32
  $("#"+unit_tag+" [data-class='wpcf7cf_group']").hide();
33
  for (var i=0; i < wpcf7cf_conditions.length; i++) {
34
 
35
  var condition = wpcf7cf_conditions[i];
 
36
 
37
+ $field = $('#'+unit_tag+' [name="'+condition.if_field+'"]').length ? $('#'+unit_tag+' [name="'+condition.if_field+'"]') : $('#'+unit_tag+' [name="'+condition.if_field+'[]"]');
38
 
39
  if ($field.length == 1) {
40
 
41
+
42
+
43
  // single field (tested with text field, single checkbox, select with single value (dropdown), select with multiple values)
44
 
45
  if ($field.is('select')) {
46
+
47
  var show = false;
48
+
49
  if(condition.operator == 'not equals') {
50
  show = true;
51
  }
52
+
53
  $field.find('option:selected').each(function () {
54
  var $option = $(this);
55
  if (condition.operator == 'equals' && $option.val() == condition.if_value) {
58
  show = false;
59
  }
60
  });
61
+
62
  if(show == true) {
63
  $('#' + unit_tag + ' #' + condition.then_field).show();
64
  }
66
  continue;
67
  }
68
 
69
+ console.log(condition);
70
+
71
+ if ($field.attr('type') == 'checkbox') {
72
+ if (
73
+ $field.is(':checked') && condition.operator == 'equals' && $field.val() == condition.if_value
74
+ || !$field.is(':checked') && condition.operator == 'not equals' && $field.val() == condition.if_value
75
+ || condition.operator == 'not equals' && $field.val() != condition.if_value
76
+ ) {
77
+ $('#'+unit_tag+' #'+condition.then_field).show();
78
+ }
79
+ } else if (condition.operator == 'equals' && $field.val() == condition.if_value || condition.operator == 'not equals' && $field.val() != condition.if_value) {
80
  $('#'+unit_tag+' #'+condition.then_field).show();
81
  }
82
 
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
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,6 +47,10 @@ Because no questions have been asked frequently about this plugin.
47
 
48
  == Changelog ==
49
 
 
 
 
 
50
  = 0.2.4 =
51
  * Fixed bug that destroyed the conditional fields in email functionality
52
 
@@ -85,27 +89,22 @@ Because no questions have been asked frequently about this plugin.
85
  * tested with WP 4.5.3
86
 
87
  = 0.1.4 =
88
-
89
  * Prevent conflicts between different forms on one page.
90
  * Prevent conflicts between multiple instances of the same form on one page. (https://wordpress.org/support/topic/bug-153)
91
  * Changed regex to convert \[group\] tags to &lt;div&gt; tags, as it was posing some conflicts with other plugins (https://wordpress.org/support/topic/plugin-influence-cf7-send-button-style)
92
 
93
  = 0.1.3 =
94
-
95
  * Removed fielset, id and class attributes for group tags, because they weren't used anyway and broke the shortcode
96
  * If extra attributes are added to the group shortcode, this will no longer break functionality (even though no attributes are supported)
97
 
98
  = 0.1.2 =
99
-
100
  * Make code work with select element that allows multiple options.
101
  * Only load javascript on pages that contain a CF7 form
102
 
103
  = 0.1.1 =
104
-
105
  Fixed bug with exclusive checkboxes (https://wordpress.org/support/topic/groups-not-showing)
106
 
107
  = 0.1 =
108
-
109
  First release
110
 
111
 
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.5
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.5 =
51
+ * Changed deprecated function wpcf7_add_shortcode to wpcf7_add_form_tag as it was causing errors in debug mode. (https://wordpress.org/support/topic/wpcf7_add_shortcode-deprecated-notice-2/)
52
+ * Removed the hide option and fixed the not-equals option for single checkboxes
53
+
54
  = 0.2.4 =
55
  * Fixed bug that destroyed the conditional fields in email functionality
56
 
89
  * tested with WP 4.5.3
90
 
91
  = 0.1.4 =
 
92
  * Prevent conflicts between different forms on one page.
93
  * Prevent conflicts between multiple instances of the same form on one page. (https://wordpress.org/support/topic/bug-153)
94
  * Changed regex to convert \[group\] tags to &lt;div&gt; tags, as it was posing some conflicts with other plugins (https://wordpress.org/support/topic/plugin-influence-cf7-send-button-style)
95
 
96
  = 0.1.3 =
 
97
  * Removed fielset, id and class attributes for group tags, because they weren't used anyway and broke the shortcode
98
  * If extra attributes are added to the group shortcode, this will no longer break functionality (even though no attributes are supported)
99
 
100
  = 0.1.2 =
 
101
  * Make code work with select element that allows multiple options.
102
  * Only load javascript on pages that contain a CF7 form
103
 
104
  = 0.1.1 =
 
105
  Fixed bug with exclusive checkboxes (https://wordpress.org/support/topic/groups-not-showing)
106
 
107
  = 0.1 =
 
108
  First release
109
 
110