Conditional Fields for Contact Form 7 - Version 1.4.2

Version Description

(04-10-19) = * Disabled mailbox syntax errors if there are group tags present. (this is overkill, and should be changed if the necassary hooks become available) https://wordpress.org/support/topic/filter-detect_invalid_mailbox_syntax/ * Checked issue: https://github.com/pwkip/contact-form-7-conditional-fields/issues/26 (nothing changed, but turns out to be working fine) * Fixed issue where mail_2 added extra lines in the email message. https://github.com/pwkip/contact-form-7-conditional-fields/issues/30 * Made the clear_on_hide property a bit more useful (https://github.com/pwkip/contact-form-7-conditional-fields/issues/27) * Got rid of warning in PHP 7 (https://wordpress.org/support/topic/compatibility-warning-message-regarding-wpcf7_admin_read_write_capability/) * Fixed some javascript errors that appeared on non-CF7CF subpages of CF7 * Tested WP version 5.1.1

Download this release

Release Info

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

Code changes from version 1.4.1 to 1.4.2

cf7cf.php CHANGED
@@ -26,10 +26,16 @@ class ContactForm7ConditionalFields {
26
 
27
  add_filter( 'wpcf7_posted_data', array($this, 'remove_hidden_post_data') );
28
  add_filter( 'wpcf7_mail_components', array($this, 'hide_hidden_mail_fields') );
29
- add_filter('wpcf7_additional_mail', array($this, 'hide_hidden_mail_fields_additional_mail'), 10, 2);
 
30
 
31
  add_filter( 'wpcf7_validate', array($this, 'skip_validation_for_hidden_fields'), 2, 2 );
32
 
 
 
 
 
 
33
  register_activation_hook(__FILE__, array($this, 'activate'));
34
 
35
  if (is_admin()) {
@@ -37,6 +43,46 @@ class ContactForm7ConditionalFields {
37
  }
38
  }
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  function activate() {
41
  //add options with add_option and stuff
42
  }
@@ -213,11 +259,12 @@ class ContactForm7ConditionalFields {
213
  return $components;
214
  }
215
 
216
- function hide_hidden_mail_fields_additional_mail($additional_mail, $contact_form) {
217
- if (!is_array($additional_mail) || !array_key_exists('mail_2', $additional_mail)) return $additional_mail;
218
- $additional_mail['mail_2'] = $this->hide_hidden_mail_fields($additional_mail['mail_2']);
219
- return $additional_mail;
220
- }
 
221
 
222
  function hide_hidden_mail_fields_regex_callback ( $matches ) {
223
  $name = $matches[1];
@@ -270,7 +317,7 @@ function wpcf7cf_properties($properties, $wpcf7form) {
270
 
271
  array_push($stack,$tag_html_type);
272
 
273
- echo '<'.$tag_html_type.' id="'.$tag_id.'" '.implode(' ',$tag_html_data).' data-class="wpcf7cf_group">';
274
  } else if ($form_part == '[/group]') {
275
  echo '</'.array_pop($stack).'>';
276
  } else {
@@ -315,4 +362,11 @@ function wpcf7cf_endswith($string, $test) {
315
  $testlen = strlen($test);
316
  if ($testlen > $strlen) return false;
317
  return substr_compare($string, $test, $strlen - $testlen, $testlen) === 0;
 
 
 
 
 
 
 
318
  }
26
 
27
  add_filter( 'wpcf7_posted_data', array($this, 'remove_hidden_post_data') );
28
  add_filter( 'wpcf7_mail_components', array($this, 'hide_hidden_mail_fields') );
29
+
30
+ //add_filter( 'wpcf7_additional_mail', array($this, 'hide_hidden_mail_fields_additional_mail'), 10, 2);
31
 
32
  add_filter( 'wpcf7_validate', array($this, 'skip_validation_for_hidden_fields'), 2, 2 );
33
 
34
+ // validation messages
35
+ add_action('wpcf7_config_validator_validate', array($this,'wpcf7cf_config_validator_validate'));
36
+
37
+
38
+
39
  register_activation_hook(__FILE__, array($this, 'activate'));
40
 
41
  if (is_admin()) {
43
  }
44
  }
45
 
46
+ /**
47
+ * Suppress invalid mailbox syntax errors on fields that contain existing conditional
48
+ */
49
+ function wpcf7cf_config_validator_validate(WPCF7_ConfigValidator $wpcf7_config_validator) {
50
+
51
+ // TODO: For now we kill every syntax error once a [groupname] tag is detected.
52
+ // Ideally, this function should check each string inside the group for invalid syntax.
53
+ // TODO 2: ajax validation not working yet, because $cf->scan_form_tags() does not seem to contain group tags if it's an ajax request. Need to investigate.
54
+
55
+ $cf = $wpcf7_config_validator->contact_form();
56
+ $all_group_tags = $cf->scan_form_tags();
57
+
58
+ foreach ($wpcf7_config_validator->collect_error_messages() as $err_type => $err) {
59
+
60
+
61
+ $parts = explode('.',$err_type);
62
+ $property = $parts[0];
63
+ $sub_prop = $parts[1];
64
+ $prop_val = $cf->prop($property)[$sub_prop];
65
+
66
+
67
+ // TODO 2: Dirty hack. Because of TODO 2 we are just going to kill the error message if we detect the string '[/'
68
+ // Start removing here.
69
+ if (strpos($prop_val, '[/') !== false) {
70
+ $wpcf7_config_validator->remove_error($err_type, WPCF7_ConfigValidator::error_invalid_mailbox_syntax);
71
+ continue;
72
+ }
73
+ // TODO 2: Stop removing here. and uncomment code below.
74
+
75
+ // foreach ($all_group_tags as $form_tag) {
76
+ // if (strpos($prop_val, '['.$form_tag->name.']') !== false) {
77
+ // $wpcf7_config_validator->remove_error($err_type, WPCF7_ConfigValidator::error_invalid_mailbox_syntax);
78
+ // }
79
+ // }
80
+
81
+ }
82
+
83
+ return new WPCF7_ConfigValidator($wpcf7_config_validator->contact_form());
84
+ }
85
+
86
  function activate() {
87
  //add options with add_option and stuff
88
  }
259
  return $components;
260
  }
261
 
262
+ // Seems like it was not needed.
263
+ // function hide_hidden_mail_fields_additional_mail($additional_mail, $contact_form) {
264
+ // if (!is_array($additional_mail) || !array_key_exists('mail_2', $additional_mail)) return $additional_mail;
265
+ // $additional_mail['mail_2'] = $this->hide_hidden_mail_fields($additional_mail['mail_2']);
266
+ // return $additional_mail;
267
+ // }
268
 
269
  function hide_hidden_mail_fields_regex_callback ( $matches ) {
270
  $name = $matches[1];
317
 
318
  array_push($stack,$tag_html_type);
319
 
320
+ echo '<'.$tag_html_type.' data-id="'.$tag_id.'" '.implode(' ',$tag_html_data).' data-class="wpcf7cf_group">';
321
  } else if ($form_part == '[/group]') {
322
  echo '</'.array_pop($stack).'>';
323
  } else {
362
  $testlen = strlen($test);
363
  if ($testlen > $strlen) return false;
364
  return substr_compare($string, $test, $strlen - $testlen, $testlen) === 0;
365
+ }
366
+
367
+ add_filter( 'wpcf7_form_tag_data_option', 'wpcf7cf_form_tag_data_option', 10, 3 );
368
+
369
+ function wpcf7cf_form_tag_data_option($output, $args, $nog) {
370
+ $data = array();
371
+ return $data;
372
  }
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.4.1
8
  Author URI: http://bdwm.be/
9
  */
10
 
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.4.2
8
  Author URI: http://bdwm.be/
9
  */
10
 
init.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
 
3
- if (!defined('WPCF7CF_VERSION')) define( 'WPCF7CF_VERSION', '1.4.1' );
4
  if (!defined('WPCF7CF_REQUIRED_WP_VERSION')) define( 'WPCF7CF_REQUIRED_WP_VERSION', '4.1' );
5
  if (!defined('WPCF7CF_PLUGIN')) define( 'WPCF7CF_PLUGIN', __FILE__ );
6
  if (!defined('WPCF7CF_PLUGIN_BASENAME')) define( 'WPCF7CF_PLUGIN_BASENAME', plugin_basename( WPCF7CF_PLUGIN ) );
1
  <?php
2
 
3
+ if (!defined('WPCF7CF_VERSION')) define( 'WPCF7CF_VERSION', '1.4.2' );
4
  if (!defined('WPCF7CF_REQUIRED_WP_VERSION')) define( 'WPCF7CF_REQUIRED_WP_VERSION', '4.1' );
5
  if (!defined('WPCF7CF_PLUGIN')) define( 'WPCF7CF_PLUGIN', __FILE__ );
6
  if (!defined('WPCF7CF_PLUGIN_BASENAME')) define( 'WPCF7CF_PLUGIN_BASENAME', plugin_basename( WPCF7CF_PLUGIN ) );
js/scripts.js CHANGED
@@ -43,6 +43,7 @@ var cf7signature_resized = 0; // for compatibility with contact-form-7-signature
43
  function display_fields(unit_tag, wpcf7cf_conditions, wpcf7cf_settings) {
44
 
45
  $current_form = $('#'+unit_tag);
 
46
 
47
  //for compatibility with contact-form-7-signature-addon
48
  if (cf7signature_resized == 0 && typeof signatures !== 'undefined' && signatures.constructor === Array && signatures.length > 0 ) {
@@ -57,167 +58,54 @@ var cf7signature_resized = 0; // for compatibility with contact-form-7-signature
57
  }
58
  }
59
 
60
- $("#"+unit_tag+" [data-class='wpcf7cf_group']").addClass('wpcf7cf-hidden');
61
 
62
  for (var i=0; i < wpcf7cf_conditions.length; i++) {
63
 
64
  var condition = wpcf7cf_conditions[i];
65
 
66
- // compatibility with conditional forms created with older versions of the plugin ( < 2.0 )
67
  if (!('and_rules' in condition)) {
68
  condition.and_rules = [{'if_field':condition.if_field,'if_value':condition.if_value,'operator':condition.operator}];
69
  }
70
 
71
- var show_group = true;
72
 
73
- for (var and_rule_i = 0; and_rule_i < condition.and_rules.length; and_rule_i++) {
74
-
75
- var condition_ok = false;
76
-
77
- var condition_and_rule = condition.and_rules[and_rule_i];
78
-
79
- var regex_patt = new RegExp(condition_and_rule.if_value,'i');
80
-
81
- $field = $('#'+unit_tag+' [name="'+condition_and_rule.if_field+'"]').length ? $('#'+unit_tag+' [name="'+condition_and_rule.if_field+'"]') : $('#'+unit_tag+' [name="'+condition_and_rule.if_field+'[]"]');
82
-
83
- if ($field.length == 1) {
84
-
85
- // single field (tested with text field, single checkbox, select with single value (dropdown), select with multiple values)
86
-
87
- if ($field.is('select')) {
88
-
89
- if(condition_and_rule.operator == 'not equals') {
90
- condition_ok = true;
91
- }
92
-
93
- $field.find('option:selected').each(function () {
94
- var $option = $(this);
95
- if (
96
- condition_and_rule.operator == 'equals' && $option.val() == condition_and_rule.if_value ||
97
- condition_and_rule.operator == 'equals (regex)' && regex_patt.test($option.val())
98
- ) {
99
- condition_ok = true;
100
- } else if (
101
- condition_and_rule.operator == 'not equals' && $option.val() == condition_and_rule.if_value ||
102
- condition_and_rule.operator == 'not equals (regex)' && !regex_patt.test($option.val())
103
- ) {
104
- condition_ok = false;
105
- }
106
- });
107
-
108
- show_group = show_group && condition_ok;
109
-
110
- continue;
111
- }
112
-
113
- if ($field.attr('type') == 'checkbox') {
114
- if (
115
- condition_and_rule.operator == 'equals' && $field.is(':checked') && $field.val() == condition_and_rule.if_value ||
116
- condition_and_rule.operator == 'not equals' && !$field.is(':checked') ||
117
- condition_and_rule.operator == 'is empty' && !$field.is(':checked') ||
118
- condition_and_rule.operator == 'not empty' && $field.is(':checked') ||
119
- condition_and_rule.operator == '>' && $field.is(':checked') && $field.val() > condition_and_rule.if_value ||
120
- condition_and_rule.operator == '<' && $field.is(':checked') && $field.val() < condition_and_rule.if_value ||
121
- condition_and_rule.operator == '>=' && $field.is(':checked') && $field.val() >= condition_and_rule.if_value ||
122
- condition_and_rule.operator == '<=' && $field.is(':checked') && $field.val() <= condition_and_rule.if_value ||
123
- condition_and_rule.operator == 'equals (regex)' && $field.is(':checked') && regex_patt.test($field.val()) ||
124
- condition_and_rule.operator == 'not equals (regex)' && !$field.is(':checked')
125
- ) {
126
- condition_ok = true;
127
- }
128
- } else if (
129
- ( condition_and_rule.operator == 'equals' && $field.val() == condition_and_rule.if_value ) ||
130
- ( condition_and_rule.operator == 'not equals' && $field.val() != condition_and_rule.if_value ) ||
131
- ( condition_and_rule.operator == 'equals (regex)' && regex_patt.test($field.val()) ) ||
132
- ( condition_and_rule.operator == 'not equals (regex)' && !regex_patt.test($field.val()) ) ||
133
- ( condition_and_rule.operator == '>' && $field.val() > condition_and_rule.if_value ) ||
134
- ( condition_and_rule.operator == '<' && $field.val() < condition_and_rule.if_value ) ||
135
- ( condition_and_rule.operator == '>=' && $field.val() >= condition_and_rule.if_value ) ||
136
- ( condition_and_rule.operator == '<=' && $field.val() <= condition_and_rule.if_value ) ||
137
- ( condition_and_rule.operator == 'is empty' && $field.val() == '' ) ||
138
- ( condition_and_rule.operator == 'not empty' && $field.val() != '' )
139
- ) {
140
- condition_ok = true;
141
- }
142
-
143
-
144
- } else if ($field.length > 1) {
145
-
146
- // multiple fields (tested with checkboxes, exclusive checkboxes, dropdown with multiple values)
147
-
148
- var all_values = [];
149
- var checked_values = [];
150
- $field.each(function() {
151
- all_values.push($(this).val());
152
- if($(this).is(':checked')) {
153
- checked_values.push($(this).val());
154
- }
155
- });
156
-
157
- var checked_value_index = $.inArray(condition_and_rule.if_value, checked_values);
158
- var value_index = $.inArray(condition_and_rule.if_value, all_values);
159
-
160
- if (
161
- ( condition_and_rule.operator == 'is empty' && checked_values.length == 0 ) ||
162
- ( condition_and_rule.operator == 'not empty' && checked_values.length > 0 )
163
- ) {
164
- condition_ok = true;
165
- }
166
-
167
-
168
- for(var ind=0; ind<checked_values.length; ind++) {
169
- if (
170
- ( condition_and_rule.operator == 'equals' && checked_values[ind] == condition_and_rule.if_value ) ||
171
- ( condition_and_rule.operator == 'not equals' && checked_values[ind] != condition_and_rule.if_value ) ||
172
- ( condition_and_rule.operator == 'equals (regex)' && regex_patt.test(checked_values[ind]) ) ||
173
- ( condition_and_rule.operator == 'not equals (regex)' && !regex_patt.test(checked_values[ind]) ) ||
174
- ( condition_and_rule.operator == '>' && checked_values[ind] > condition_and_rule.if_value ) ||
175
- ( condition_and_rule.operator == '<' && checked_values[ind] < condition_and_rule.if_value ) ||
176
- ( condition_and_rule.operator == '>=' && checked_values[ind] >= condition_and_rule.if_value ) ||
177
- ( condition_and_rule.operator == '<=' && checked_values[ind] <= condition_and_rule.if_value )
178
- ) {
179
- condition_ok = true;
180
- }
181
- }
182
- }
183
- show_group = show_group && condition_ok;
184
- }
185
  if (show_group) {
186
- $('#'+unit_tag+' #'+condition.then_field).removeClass('wpcf7cf-hidden');
187
  }
188
  }
189
 
190
  var animation_intime = parseInt(wpcf7cf_settings.animation_intime);
191
  var animation_outtime = parseInt(wpcf7cf_settings.animation_outtime);
192
 
193
- if (wpcf7cf_settings.animation == 'no') {
194
  animation_intime = 0;
195
  animation_outtime = 0;
196
  }
197
 
198
- $("#" + unit_tag + " [data-class='wpcf7cf_group']").each(function (index) {
199
  $group = $(this);
200
  if ($group.is(':animated')) $group.finish(); // stop any current animations on the group
201
- if ($group.css('display') == 'none' && !$group.hasClass('wpcf7cf-hidden')) {
202
- if ($group.prop('tagName') == 'SPAN') {
203
  $group.show().trigger('wpcf7cf_show_group');
204
  } else {
205
  $group.animate(show_animation, animation_intime).trigger('wpcf7cf_show_group'); // show
206
  }
207
- } else if ($group.css('display') != 'none' && $group.hasClass('wpcf7cf-hidden')) {
208
- console.log($group.prop('tagName'));
209
- if ($group.prop('tagName') == 'SPAN') {
210
- $group.hide().trigger('wpcf7cf_show_group');
211
  } else {
212
  $group.animate(hide_animation, animation_outtime).trigger('wpcf7cf_hide_group'); // hide
213
  }
214
 
215
  if ($group.attr('data-clear_on_hide') !== undefined) {
216
- $(':input', $group)
217
- .not(':button, :submit, :reset, :hidden')
218
- .val('')
219
- .prop('checked', false)
220
- .prop('selected', false);
221
  }
222
  }
223
  });
@@ -266,12 +154,12 @@ var cf7signature_resized = 0; // for compatibility with contact-form-7-signature
266
  $form.find('[data-class="wpcf7cf_group"]').each(function () {
267
  var $this = $(this);
268
  if ($this.hasClass('wpcf7cf-hidden')) {
269
- hidden_groups.push($this.attr('id'));
270
  $this.find('input,select,textarea').each(function () {
271
  hidden_fields.push($(this).attr('name'));
272
  });
273
  } else {
274
- visible_groups.push($this.attr('id'));
275
  }
276
  });
277
 
@@ -302,55 +190,134 @@ var cf7signature_resized = 0; // for compatibility with contact-form-7-signature
302
  });
303
  };
304
 
305
- // PRO ONLY
306
-
307
- $('.wpcf7cf_repeater').each(init_repeater);
308
-
309
- function init_repeater(i) {
310
- var $repeater = $(this);
311
- $repeater.$last_sub = undefined;
312
- $repeater.num_subs = 0;
313
- $repeater.id = $repeater.attr('id');
314
- var $repeater_sub = $repeater.find('.wpcf7cf_repeater_sub').eq(0);
315
- var $repeater_controls = $repeater.find('.wpcf7cf_repeater_controls').eq(0);
316
-
317
- $('.wpcf7cf_add',$repeater).click({
318
- $repeater:$repeater,
319
- $repeater_sub:$repeater_sub,
320
- repeater_sub_html:$repeater_sub[0].outerHTML,
321
- $repeater_controls:$repeater_controls
322
- }, repeater_add_sub);
323
-
324
- $('.wpcf7cf_remove',$repeater).click({
325
- $repeater:$repeater,
326
- $repeater_sub:$repeater_sub,
327
- $repeater_controls:$repeater_controls
328
- },repeater_remove_sub);
329
- }
330
 
331
- function repeater_add_sub(e) {
332
- var $repeater = e.data.$repeater;
333
- var $repeater_sub = e.data.$repeater_sub;
334
- var $repeater_controls = e.data.$repeater_controls;
335
 
336
- $repeater_controls.before(e.data.repeater_sub_html.replace(/name="(.*?)"/g,'name="wpcf7cf_repeater['+$repeater.id+']['+$repeater.num_subs+'][$1]"'));
337
 
338
- $repeater.num_subs++;
339
- return false;
340
- }
 
 
 
 
 
 
341
 
342
- function repeater_remove_sub(e) {
343
- var $repeater = e.data.$repeater;
344
- var $repeater_sub = e.data.$repeater_sub;
345
- var $repeater_controls = e.data.$repeater_controls;
346
 
347
- if ($repeater.num_subs <= 0) return;
348
- $('.wpcf7cf_repeater_sub',$repeater).last().remove();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
349
 
350
- $repeater.num_subs--;
351
- return false;
352
  }
353
 
354
- // END PRO ONLY
 
355
 
356
  })( jQuery );
43
  function display_fields(unit_tag, wpcf7cf_conditions, wpcf7cf_settings) {
44
 
45
  $current_form = $('#'+unit_tag);
46
+ $groups = $("[data-class='wpcf7cf_group']",$current_form);
47
 
48
  //for compatibility with contact-form-7-signature-addon
49
  if (cf7signature_resized == 0 && typeof signatures !== 'undefined' && signatures.constructor === Array && signatures.length > 0 ) {
58
  }
59
  }
60
 
61
+ $groups.addClass('wpcf7cf-hidden');
62
 
63
  for (var i=0; i < wpcf7cf_conditions.length; i++) {
64
 
65
  var condition = wpcf7cf_conditions[i];
66
 
67
+ // compatibility with conditional forms created with older versions of the plugin ( < 1.4 )
68
  if (!('and_rules' in condition)) {
69
  condition.and_rules = [{'if_field':condition.if_field,'if_value':condition.if_value,'operator':condition.operator}];
70
  }
71
 
72
+ var show_group = should_group_be_shown(condition, $current_form);
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  if (show_group) {
75
+ $('[data-id='+condition.then_field+']',$current_form).eq(0).removeClass('wpcf7cf-hidden');
76
  }
77
  }
78
 
79
  var animation_intime = parseInt(wpcf7cf_settings.animation_intime);
80
  var animation_outtime = parseInt(wpcf7cf_settings.animation_outtime);
81
 
82
+ if (wpcf7cf_settings.animation === 'no') {
83
  animation_intime = 0;
84
  animation_outtime = 0;
85
  }
86
 
87
+ $groups.each(function (index) {
88
  $group = $(this);
89
  if ($group.is(':animated')) $group.finish(); // stop any current animations on the group
90
+ if ($group.css('display') === 'none' && !$group.hasClass('wpcf7cf-hidden')) {
91
+ if ($group.prop('tagName') === 'SPAN') {
92
  $group.show().trigger('wpcf7cf_show_group');
93
  } else {
94
  $group.animate(show_animation, animation_intime).trigger('wpcf7cf_show_group'); // show
95
  }
96
+ } else if ($group.css('display') !== 'none' && $group.hasClass('wpcf7cf-hidden')) {
97
+ if ($group.prop('tagName') === 'SPAN') {
98
+ $group.hide().trigger('wpcf7cf_hide_group');
 
99
  } else {
100
  $group.animate(hide_animation, animation_outtime).trigger('wpcf7cf_hide_group'); // hide
101
  }
102
 
103
  if ($group.attr('data-clear_on_hide') !== undefined) {
104
+ $inputs = $(':input', $group).not(':button, :submit, :reset, :hidden');
105
+ $inputs.prop('checked', false).prop('selected', false).prop('selectedIndex', 0);
106
+ $inputs.not('[type=checkbox],[type=radio],select').val('');
107
+ $inputs.change();
108
+ //display_fields();
109
  }
110
  }
111
  });
154
  $form.find('[data-class="wpcf7cf_group"]').each(function () {
155
  var $this = $(this);
156
  if ($this.hasClass('wpcf7cf-hidden')) {
157
+ hidden_groups.push($this.data('id'));
158
  $this.find('input,select,textarea').each(function () {
159
  hidden_fields.push($(this).attr('name'));
160
  });
161
  } else {
162
+ visible_groups.push($this.data('id'));
163
  }
164
  });
165
 
190
  });
191
  };
192
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
 
 
 
 
 
194
 
 
195
 
196
+ function should_group_be_shown(condition, $current_form) {
197
+
198
+ var show_group = true;
199
+
200
+ for (var and_rule_i = 0; and_rule_i < condition.and_rules.length; and_rule_i++) {
201
+
202
+ var condition_ok = false;
203
+
204
+ var condition_and_rule = condition.and_rules[and_rule_i];
205
 
206
+ var regex_patt = new RegExp(condition_and_rule.if_value, 'i');
 
 
 
207
 
208
+ $field = $('[name="' + condition_and_rule.if_field + '"], [name="' + condition_and_rule.if_field + '[]"], [data-original-name="' + condition_and_rule.if_field + '"], [data-original-name="' + condition_and_rule.if_field + '[]"]',$current_form); //, [data-original-name="' + condition_and_rule.if_field + '"]
209
+
210
+ //TODO: ignore everything outside the sub_repeater if field is inside sub_repeater
211
+
212
+ if ($field.length == 1) {
213
+
214
+ // single field (tested with text field, single checkbox, select with single value (dropdown), select with multiple values)
215
+
216
+ if ($field.is('select')) {
217
+
218
+ if (condition_and_rule.operator == 'not equals') {
219
+ condition_ok = true;
220
+ }
221
+
222
+ $field.find('option:selected').each(function () {
223
+ var $option = $(this);
224
+ if (
225
+ condition_and_rule.operator == 'equals' && $option.val() == condition_and_rule.if_value ||
226
+ condition_and_rule.operator == 'equals (regex)' && regex_patt.test($option.val())
227
+ ) {
228
+ condition_ok = true;
229
+ } else if (
230
+ condition_and_rule.operator == 'not equals' && $option.val() == condition_and_rule.if_value ||
231
+ condition_and_rule.operator == 'not equals (regex)' && !regex_patt.test($option.val())
232
+ ) {
233
+ condition_ok = false;
234
+ }
235
+ });
236
+
237
+ show_group = show_group && condition_ok;
238
+
239
+ return show_group;
240
+ }
241
+
242
+ if ($field.attr('type') == 'checkbox') {
243
+ if (
244
+ condition_and_rule.operator == 'equals' && $field.is(':checked') && $field.val() == condition_and_rule.if_value ||
245
+ condition_and_rule.operator == 'not equals' && !$field.is(':checked') ||
246
+ condition_and_rule.operator == 'is empty' && !$field.is(':checked') ||
247
+ condition_and_rule.operator == 'not empty' && $field.is(':checked') ||
248
+ condition_and_rule.operator == '>' && $field.is(':checked') && $field.val() > condition_and_rule.if_value ||
249
+ condition_and_rule.operator == '<' && $field.is(':checked') && $field.val() < condition_and_rule.if_value ||
250
+ condition_and_rule.operator == '>=' && $field.is(':checked') && $field.val() >= condition_and_rule.if_value ||
251
+ condition_and_rule.operator == '<=' && $field.is(':checked') && $field.val() <= condition_and_rule.if_value ||
252
+ condition_and_rule.operator == 'equals (regex)' && $field.is(':checked') && regex_patt.test($field.val()) ||
253
+ condition_and_rule.operator == 'not equals (regex)' && !$field.is(':checked')
254
+ ) {
255
+ condition_ok = true;
256
+ }
257
+ } else if (
258
+ ( condition_and_rule.operator == 'equals' && $field.val() == condition_and_rule.if_value ) ||
259
+ ( condition_and_rule.operator == 'not equals' && $field.val() != condition_and_rule.if_value ) ||
260
+ ( condition_and_rule.operator == 'equals (regex)' && regex_patt.test($field.val()) ) ||
261
+ ( condition_and_rule.operator == 'not equals (regex)' && !regex_patt.test($field.val()) ) ||
262
+ ( condition_and_rule.operator == '>' && $field.val() > condition_and_rule.if_value ) ||
263
+ ( condition_and_rule.operator == '<' && $field.val() < condition_and_rule.if_value ) ||
264
+ ( condition_and_rule.operator == '>=' && $field.val() >= condition_and_rule.if_value ) ||
265
+ ( condition_and_rule.operator == '<=' && $field.val() <= condition_and_rule.if_value ) ||
266
+ ( condition_and_rule.operator == 'is empty' && $field.val() == '' ) ||
267
+ ( condition_and_rule.operator == 'not empty' && $field.val() != '' )
268
+ ) {
269
+ condition_ok = true;
270
+ }
271
+
272
+
273
+ } else if ($field.length > 1) {
274
+
275
+ // multiple fields (tested with checkboxes, exclusive checkboxes, dropdown with multiple values)
276
+
277
+ var all_values = [];
278
+ var checked_values = [];
279
+ $field.each(function () {
280
+ all_values.push($(this).val());
281
+ if ($(this).is(':checked')) {
282
+ checked_values.push($(this).val());
283
+ }
284
+ });
285
+
286
+ var checked_value_index = $.inArray(condition_and_rule.if_value, checked_values);
287
+ var value_index = $.inArray(condition_and_rule.if_value, all_values);
288
+
289
+ if (
290
+ ( condition_and_rule.operator == 'is empty' && checked_values.length == 0 ) ||
291
+ ( condition_and_rule.operator == 'not empty' && checked_values.length > 0 )
292
+ ) {
293
+ condition_ok = true;
294
+ }
295
+
296
+
297
+ for (var ind = 0; ind < checked_values.length; ind++) {
298
+ if (
299
+ ( condition_and_rule.operator == 'equals' && checked_values[ind] == condition_and_rule.if_value ) ||
300
+ ( condition_and_rule.operator == 'not equals' && checked_values[ind] != condition_and_rule.if_value ) ||
301
+ ( condition_and_rule.operator == 'equals (regex)' && regex_patt.test(checked_values[ind]) ) ||
302
+ ( condition_and_rule.operator == 'not equals (regex)' && !regex_patt.test(checked_values[ind]) ) ||
303
+ ( condition_and_rule.operator == '>' && checked_values[ind] > condition_and_rule.if_value ) ||
304
+ ( condition_and_rule.operator == '<' && checked_values[ind] < condition_and_rule.if_value ) ||
305
+ ( condition_and_rule.operator == '>=' && checked_values[ind] >= condition_and_rule.if_value ) ||
306
+ ( condition_and_rule.operator == '<=' && checked_values[ind] <= condition_and_rule.if_value )
307
+ ) {
308
+ condition_ok = true;
309
+ }
310
+ }
311
+ }
312
+
313
+ show_group = show_group && condition_ok;
314
+ }
315
+
316
+ return show_group;
317
 
 
 
318
  }
319
 
320
+
321
+ //removed pro functions
322
 
323
  })( jQuery );
js/scripts_admin.js CHANGED
@@ -2,331 +2,336 @@
2
  * Created by jules on 7/17/2015.
3
  */
4
  var $wpcf7cf_new_entry = jQuery('#wpcf7cf-new-entry').eq(0);
5
- var wpcf7cf_new_and_rule_html = $wpcf7cf_new_entry.find('.wpcf7cf-and-rule')[0].outerHTML;
6
- var wpcf7cf_new_entry_html = $wpcf7cf_new_entry.html();
7
-
8
- var regex = /show \[(.*)\] if \[(.*)\] (equals|not equals|equals \(regex\)|not equals \(regex\)|>|>=|<=|<|is empty|not empty) "(.*)"/g;
9
- var regex_and = /and if \[(.*)\] (equals|not equals|equals \(regex\)|not equals \(regex\)|>|>=|<=|<|is empty|not empty) "(.*)"/g;
10
-
11
-
12
- if (_wpcf7 == null) { var _wpcf7 = wpcf7}; // wpcf7 4.8 fix
13
-
14
- var old_compose = _wpcf7.taggen.compose;
15
-
16
- var regexes = [
17
- { label: wpcf7cf_options_0.regex_email_label, desc: wpcf7cf_options_0.regex_email },
18
- { label: wpcf7cf_options_0.regex_numeric_label, desc: wpcf7cf_options_0.regex_numeric },
19
- { label: wpcf7cf_options_0.regex_alphanumeric_label, desc: wpcf7cf_options_0.regex_alphanumeric },
20
- { label: wpcf7cf_options_0.regex_alphabetic_label, desc: wpcf7cf_options_0.regex_alphabetic },
21
- { label: wpcf7cf_options_0.regex_date_label, desc: wpcf7cf_options_0.regex_date },
22
- { label: wpcf7cf_options_0.regex_custom_1_label, desc: wpcf7cf_options_0.regex_custom_1 },
23
- { label: wpcf7cf_options_0.regex_custom_2_label, desc: wpcf7cf_options_0.regex_custom_2 },
24
- { label: wpcf7cf_options_0.regex_custom_3_label, desc: wpcf7cf_options_0.regex_custom_3 },
25
- { label: wpcf7cf_options_0.regex_custom_4_label, desc: wpcf7cf_options_0.regex_custom_4 },
26
- { label: wpcf7cf_options_0.regex_custom_5_label, desc: wpcf7cf_options_0.regex_custom_5 },
27
- ];
28
-
29
- var i = regexes.length;
30
- while (i--) {
31
- if (null == regexes[i].label || null == regexes[i].desc || regexes[i].label == '' || regexes[i].desc == '') {
32
- regexes.splice(i,1);
33
- }
34
- }
35
 
36
- var termTemplate = "<span class='ui-autocomplete-term'>%s</span>";
37
 
38
- (function($) {
 
39
 
40
- $('#wpcf7cf-entries').sortable();
41
- $(('.wpcf7cf-and-rules')).sortable();
42
 
43
 
44
- // ...before overwriting the jQuery extension point
45
- _wpcf7.taggen.compose = function(tagType, $form)
46
- {
47
 
48
- $('#tag-generator-panel-group-style-hidden').val($('#tag-generator-panel-group-style').val());
49
 
50
- // original behavior - use function.apply to preserve context
51
- var ret = old_compose.apply(this, arguments);
52
- //tagType = arguments[0];
53
- //$form = arguments[1];
 
 
 
 
 
 
 
 
54
 
55
- // START: code here will be executed after the _wpcf7.taggen.update function
56
- if (tagType== 'group') ret += "[/group]";
57
- if (tagType== 'repeater') ret += "[/repeater]";
 
 
 
58
 
59
- // END
60
 
61
- if (tagType== 'togglebutton') {
62
- $val1 = $('#tag-generator-panel-togglebutton-value-1');
63
- $val2 = $('#tag-generator-panel-togglebutton-value-2');
64
- var val1 = $val1.val();
65
- var val2 = $val2.val();
66
 
67
- if (val1 == "") val1 = $val1.data('default');
68
- if (val2 == "") val2 = $val2.data('default');
69
 
70
- str_val = ' "'+val1+'" "'+val2+'"';
71
 
72
- ret = ret.replace(']', str_val+']');
73
- }
 
74
 
75
- return ret;
76
- };
77
 
78
- var index = $('#wpcf7cf-entries .entry').length;
79
- var index_and = 0;
 
 
80
 
81
- $('#wpcf7cf-add-button').click(function(){
 
 
82
 
83
- var id = add_condition_fields();
84
 
85
- return false;
 
 
 
 
86
 
87
- });
 
88
 
89
- function clear_all_condition_fields() {
90
- $('.entry').remove();
91
- }
92
 
93
- function add_condition_fields() {
94
- $('<div class="entry" id="entry-'+index+'">'+(wpcf7cf_new_entry_html.replace(/{id}/g, index))+'</div>').appendTo('#wpcf7cf-entries');
95
- index++;
96
- update_entries();
97
- return (index-1);
98
- }
99
 
100
- function add_and_condition_fields(id) {
101
- // $('#entry-'+id+' .wpcf7cf-and-rules').eq(0).append($wpcf7cf_new_and_rule.clone());
102
- $('#entry-'+id+' .wpcf7cf-and-rules').eq(0).append(wpcf7cf_new_and_rule_html.replace(/{id}/g, index-1).replace(/\[and_rules\]\[0\]/g, '[and_rules]['+index_and+']'));
103
- index_and++;
104
- return (index_and-1);
105
- }
106
 
107
- function import_condition_fields() {
 
108
 
109
- $if_values = $('.if-value');
110
 
111
- var lines = $('#wpcf7cf-settings-text').val().split(/\r?\n/);
112
 
113
- var id = -1;
114
 
115
- for (var i = 0; i<lines.length; i++) {
116
 
117
- var str = lines[i];
 
 
118
 
119
- var match = regex.exec(str);
 
 
 
 
 
120
 
121
- if (match != null) {
 
 
 
 
 
122
 
123
- index_and = 0; // reset this for each first condition (This one has and_index [0]).
124
 
125
- id = add_condition_fields();
126
 
127
- $('#entry-'+id+' .then-field-select').val(match[1]);
128
- $('#entry-'+id+' .if-field-select').val(match[2]);
129
- $('#entry-'+id+' .operator').val(match[3]);
130
- $('#entry-'+id+' .if-value').val(match[4]);
131
 
132
- index_and = 1; // the next and condition will gave and_index[1];
133
 
134
- regex.lastIndex = 0;
135
 
136
- }
137
 
138
- match = regex_and.exec(str);
139
 
140
- if (match != null && id != -1) {
141
 
142
- var and_id = add_and_condition_fields(id);
143
 
144
- $('#entry-'+id+' .wpcf7cf-and-rule:last-child .if-field-select').val(match[1]);
145
- $('#entry-'+id+' .wpcf7cf-and-rule:last-child .operator').val(match[2]);
146
- $('#entry-'+id+' .wpcf7cf-and-rule:last-child .if-value').val(match[3]);
147
 
148
- regex_and.lastIndex = 0;
 
 
 
149
 
150
- }
151
- }
152
- }
153
 
154
- // export/import settings
155
 
156
- $('#wpcf7cf-settings-text-wrap').hide();
157
 
158
- $('#wpcf7cf-settings-to-text').click(function() {
159
- $('#wpcf7cf-settings-text-wrap').show();
160
 
161
- $('#wpcf7cf-settings-text').val('');
162
- $('#wpcf7cf-entries .entry').each(function() {
163
- var $entry = $(this);
164
- var line = 'show [' + $entry.find('.then-field-select').val() + ']';
165
- var text_indent = line.length-3;
166
- $entry.find('.wpcf7cf-and-rule').each(function(i) {
167
- $and_rule = $(this);
168
- if (i>0) {
169
 
170
- line += '\n'+' '.repeat(text_indent)+'and';
171
 
172
- }
173
- line += ' if [' + $and_rule.find('.if-field-select').val() + ']'
174
- + ' ' + $and_rule.find('.operator').val()
175
- + ' "' + $and_rule.find('.if-value').val() + '"';
176
- });
177
- $('#wpcf7cf-settings-text').val($('#wpcf7cf-settings-text').val() + line + "\n" ).select();
178
- });
179
- return false;
180
- });
181
 
182
- $if_values = $('.if-value');
183
 
184
- $('#add-fields').click(function() {
185
- import_condition_fields();
186
- update_entries();
187
- return false;
188
- });
189
 
190
- $('#overwrite-fields').click(function() {
191
- clear_all_condition_fields();
192
- import_condition_fields();
193
- update_entries();
194
- return false;
195
- });
196
 
197
- $('#wpcf7cf-settings-text-clear').click(function() {
198
  $('#wpcf7cf-settings-text-wrap').hide();
199
- $('#wpcf7cf-settings-text').val('');
200
- return false;
201
- });
202
 
203
- function update_entries() {
204
- $if_values = $('.if-value');
205
- init_autocomplete();
206
- $if_values.css({'visibility':'visible'});
207
- $if_values.autocomplete( "disable" );
208
-
209
- $('#wpcf7cf-entries .wpcf7cf-and-rule').each(function() {
210
- var $and_rule = $(this);
211
- if ($and_rule.find('.operator').eq(0).val() === 'is empty' || $and_rule.find('.operator').eq(0).val() === 'not empty') {
212
- $and_rule.find('.if-value').eq(0).css({'visibility':'hidden'});
213
- } else if ($and_rule.find('.operator').eq(0).val().endsWith('(regex)')) {
214
- $and_rule.find('.if-value').eq(0).autocomplete( "enable" );
215
- }
216
- });
217
 
218
- scale_and_button();
 
 
 
 
 
 
 
219
 
220
- set_events();
221
- }
222
 
223
- function init_autocomplete() {
224
-
225
- $if_values.autocomplete({
226
- disabled: true,
227
- source: function(request, response) {
228
- var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
229
- response($.grep(regexes, function(value) {
230
- return matcher.test(value.label || value.value || value) || matcher.test(value.desc);
231
- }));
232
- },
233
- focus: function( event, ui ) {
234
- $( event.target ).val( ui.item.desc );
235
- return false;
236
- },
237
- select: function( event, ui ) {
238
- $( event.target ).val( ui.item.desc );
239
- return false;
240
- },
241
- open: function(e,ui) {
242
- $el = $(e.target);
243
- var styledTerm = termTemplate.replace('%s', $el.val());
244
-
245
- $('.ui-autocomplete').find('em').each(function() {
246
- var me = $(this);
247
- me.html( me.text().replace($el.val(), styledTerm) );
248
  });
249
- },
250
- minLength: 0
251
- }).each(function() {
252
- $(this).autocomplete( "instance" )._renderItem = function( ul, item ) {
253
- return $("<li>")
254
- .append("<div><em>" + item.label + "</em><br><em>" + item.desc + "</em></div>")
255
- .appendTo(ul);
256
- }
257
- });
258
- $if_values.on('focus', function() {
259
- $(this).autocomplete("search");
260
  });
261
- }
262
-
263
- update_entries();
264
 
265
- function set_events() { // called at the end of update_entries
266
-
267
- $('.wpcf7cf-and-rules').sortable();
268
 
269
- $('.and-button').off('click').click(function() {
270
- $this = $(this);
271
- $andblock = $this.closest('.wpcf7cf-and-rule');
272
- $andblocks_container = $this.closest('.wpcf7cf-and-rules');
273
- next_index = $andblocks_container.data('next-index');
274
- $andblocks_container.data('next-index',next_index+1);
275
- var and_i = next_index;
276
- clone_html = $andblock.get(0).outerHTML.replace(/wpcf7cf_options\[([0-9]*)\]\[and_rules\]\[([0-9]*)\]/g, 'wpcf7cf_options[$1][and_rules]['+and_i+']');
277
- $andblock.after(clone_html);
278
  update_entries();
279
  return false;
280
  });
281
 
282
- $('.delete-button').off('click').click(function(){
283
- $and_rule = $(this).closest('.wpcf7cf-and-rule');
284
- if ($and_rule.siblings().length > 0) {
285
- $and_rule.remove();
286
- } else {
287
- $and_rule[0].closest('.entry').remove();
288
- }
289
-
290
  update_entries();
291
-
292
  return false;
293
  });
294
 
295
- $('.operator').off('change').change(function() {
296
- update_entries();
 
297
  return false;
298
  });
299
- }
300
 
301
- function scale_and_button() {
302
- $('.wpcf7cf-and-rule:first-child .and-button').each(function(){
303
- $and_button = $(this);
304
- num_and_rules = $and_button.closest('.wpcf7cf-and-rule').siblings().length+1;
305
- var height = (34*num_and_rules-12)+'px';
306
- $and_button.css({'height':height,'line-height':height});
307
- });
308
- }
 
 
 
 
 
 
309
 
310
- // ------------------------------------
311
- // OPTIONS PAGE
312
- // ------------------------------------
313
 
314
- $(document).ready(function() {
 
315
 
316
- $('.wpcf7cf-options-notice .notice-dismiss-2').click(function () {
317
- $('.wpcf7cf-options-notice .notice-dismiss').click();
318
- });
319
- $('.wpcf7cf-options-notice .notice-dismiss').click(function () {
320
- wpcf7cf_dismiss_notice();
321
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
322
 
323
- function wpcf7cf_dismiss_notice() {
324
- $('input[name="wpcf7cf_options[notice_dismissed]"]').val('true');
325
- $.post(ajaxurl, {action:'wpcf7cf_dismiss_notice'}, function(response) {
326
- // nothing to do. dismiss_notice option should be set to TRUE server side by now.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
327
  });
328
  }
329
 
330
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
331
 
332
- })( jQuery );
2
  * Created by jules on 7/17/2015.
3
  */
4
  var $wpcf7cf_new_entry = jQuery('#wpcf7cf-new-entry').eq(0);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
+ if ($wpcf7cf_new_entry.length > 0) {
7
 
8
+ var wpcf7cf_new_and_rule_html = $wpcf7cf_new_entry.find('.wpcf7cf-and-rule')[0].outerHTML;
9
+ var wpcf7cf_new_entry_html = $wpcf7cf_new_entry.html();
10
 
11
+ var regex = /show \[(.*)\] if \[(.*)\] (equals|not equals|equals \(regex\)|not equals \(regex\)|>|>=|<=|<|is empty|not empty) "(.*)"/g;
12
+ var regex_and = /and if \[(.*)\] (equals|not equals|equals \(regex\)|not equals \(regex\)|>|>=|<=|<|is empty|not empty) "(.*)"/g;
13
 
14
 
15
+ if (_wpcf7 == null) { var _wpcf7 = wpcf7}; // wpcf7 4.8 fix
 
 
16
 
17
+ var old_compose = _wpcf7.taggen.compose;
18
 
19
+ var regexes = [
20
+ { label: wpcf7cf_options_0.regex_email_label, desc: wpcf7cf_options_0.regex_email },
21
+ { label: wpcf7cf_options_0.regex_numeric_label, desc: wpcf7cf_options_0.regex_numeric },
22
+ { label: wpcf7cf_options_0.regex_alphanumeric_label, desc: wpcf7cf_options_0.regex_alphanumeric },
23
+ { label: wpcf7cf_options_0.regex_alphabetic_label, desc: wpcf7cf_options_0.regex_alphabetic },
24
+ { label: wpcf7cf_options_0.regex_date_label, desc: wpcf7cf_options_0.regex_date },
25
+ { label: wpcf7cf_options_0.regex_custom_1_label, desc: wpcf7cf_options_0.regex_custom_1 },
26
+ { label: wpcf7cf_options_0.regex_custom_2_label, desc: wpcf7cf_options_0.regex_custom_2 },
27
+ { label: wpcf7cf_options_0.regex_custom_3_label, desc: wpcf7cf_options_0.regex_custom_3 },
28
+ { label: wpcf7cf_options_0.regex_custom_4_label, desc: wpcf7cf_options_0.regex_custom_4 },
29
+ { label: wpcf7cf_options_0.regex_custom_5_label, desc: wpcf7cf_options_0.regex_custom_5 },
30
+ ];
31
 
32
+ var i = regexes.length;
33
+ while (i--) {
34
+ if (null == regexes[i].label || null == regexes[i].desc || regexes[i].label == '' || regexes[i].desc == '') {
35
+ regexes.splice(i,1);
36
+ }
37
+ }
38
 
39
+ var termTemplate = "<span class='ui-autocomplete-term'>%s</span>";
40
 
41
+ (function($) {
 
 
 
 
42
 
43
+ $('#wpcf7cf-entries').sortable();
44
+ $(('.wpcf7cf-and-rules')).sortable();
45
 
 
46
 
47
+ // ...before overwriting the jQuery extension point
48
+ _wpcf7.taggen.compose = function(tagType, $form)
49
+ {
50
 
51
+ $('#tag-generator-panel-group-style-hidden').val($('#tag-generator-panel-group-style').val());
 
52
 
53
+ // original behavior - use function.apply to preserve context
54
+ var ret = old_compose.apply(this, arguments);
55
+ //tagType = arguments[0];
56
+ //$form = arguments[1];
57
 
58
+ // START: code here will be executed after the _wpcf7.taggen.update function
59
+ if (tagType== 'group') ret += "[/group]";
60
+ if (tagType== 'repeater') ret += "[/repeater]";
61
 
62
+ // END
63
 
64
+ if (tagType== 'togglebutton') {
65
+ $val1 = $('#tag-generator-panel-togglebutton-value-1');
66
+ $val2 = $('#tag-generator-panel-togglebutton-value-2');
67
+ var val1 = $val1.val();
68
+ var val2 = $val2.val();
69
 
70
+ if (val1 == "") val1 = $val1.data('default');
71
+ if (val2 == "") val2 = $val2.data('default');
72
 
73
+ str_val = ' "'+val1+'" "'+val2+'"';
 
 
74
 
75
+ ret = ret.replace(']', str_val+']');
76
+ }
 
 
 
 
77
 
78
+ return ret;
79
+ };
 
 
 
 
80
 
81
+ var index = $('#wpcf7cf-entries .entry').length;
82
+ var index_and = 0;
83
 
84
+ $('#wpcf7cf-add-button').click(function(){
85
 
86
+ var id = add_condition_fields();
87
 
88
+ return false;
89
 
90
+ });
91
 
92
+ function clear_all_condition_fields() {
93
+ $('.entry').remove();
94
+ }
95
 
96
+ function add_condition_fields() {
97
+ $('<div class="entry" id="entry-'+index+'">'+(wpcf7cf_new_entry_html.replace(/{id}/g, index))+'</div>').appendTo('#wpcf7cf-entries');
98
+ index++;
99
+ update_entries();
100
+ return (index-1);
101
+ }
102
 
103
+ function add_and_condition_fields(id) {
104
+ // $('#entry-'+id+' .wpcf7cf-and-rules').eq(0).append($wpcf7cf_new_and_rule.clone());
105
+ $('#entry-'+id+' .wpcf7cf-and-rules').eq(0).append(wpcf7cf_new_and_rule_html.replace(/{id}/g, index-1).replace(/\[and_rules\]\[0\]/g, '[and_rules]['+index_and+']'));
106
+ index_and++;
107
+ return (index_and-1);
108
+ }
109
 
110
+ function import_condition_fields() {
111
 
112
+ $if_values = $('.if-value');
113
 
114
+ var lines = $('#wpcf7cf-settings-text').val().split(/\r?\n/);
 
 
 
115
 
116
+ var id = -1;
117
 
118
+ for (var i = 0; i<lines.length; i++) {
119
 
120
+ var str = lines[i];
121
 
122
+ var match = regex.exec(str);
123
 
124
+ if (match != null) {
125
 
126
+ index_and = 0; // reset this for each first condition (This one has and_index [0]).
127
 
128
+ id = add_condition_fields();
 
 
129
 
130
+ $('#entry-'+id+' .then-field-select').val(match[1]);
131
+ $('#entry-'+id+' .if-field-select').val(match[2]);
132
+ $('#entry-'+id+' .operator').val(match[3]);
133
+ $('#entry-'+id+' .if-value').val(match[4]);
134
 
135
+ index_and = 1; // the next and condition will gave and_index[1];
 
 
136
 
137
+ regex.lastIndex = 0;
138
 
139
+ }
140
 
141
+ match = regex_and.exec(str);
 
142
 
143
+ if (match != null && id != -1) {
 
 
 
 
 
 
 
144
 
145
+ var and_id = add_and_condition_fields(id);
146
 
147
+ $('#entry-'+id+' .wpcf7cf-and-rule:last-child .if-field-select').val(match[1]);
148
+ $('#entry-'+id+' .wpcf7cf-and-rule:last-child .operator').val(match[2]);
149
+ $('#entry-'+id+' .wpcf7cf-and-rule:last-child .if-value').val(match[3]);
 
 
 
 
 
 
150
 
151
+ regex_and.lastIndex = 0;
152
 
153
+ }
154
+ }
155
+ }
 
 
156
 
157
+ // export/import settings
 
 
 
 
 
158
 
 
159
  $('#wpcf7cf-settings-text-wrap').hide();
 
 
 
160
 
161
+ $('#wpcf7cf-settings-to-text').click(function() {
162
+ $('#wpcf7cf-settings-text-wrap').show();
 
 
 
 
 
 
 
 
 
 
 
 
163
 
164
+ $('#wpcf7cf-settings-text').val('');
165
+ $('#wpcf7cf-entries .entry').each(function() {
166
+ var $entry = $(this);
167
+ var line = 'show [' + $entry.find('.then-field-select').val() + ']';
168
+ var text_indent = line.length-3;
169
+ $entry.find('.wpcf7cf-and-rule').each(function(i) {
170
+ $and_rule = $(this);
171
+ if (i>0) {
172
 
173
+ line += '\n'+' '.repeat(text_indent)+'and';
 
174
 
175
+ }
176
+ line += ' if [' + $and_rule.find('.if-field-select').val() + ']'
177
+ + ' ' + $and_rule.find('.operator').val()
178
+ + ' "' + $and_rule.find('.if-value').val() + '"';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
  });
180
+ $('#wpcf7cf-settings-text').val($('#wpcf7cf-settings-text').val() + line + "\n" ).select();
181
+ });
182
+ return false;
 
 
 
 
 
 
 
 
183
  });
 
 
 
184
 
185
+ $if_values = $('.if-value');
 
 
186
 
187
+ $('#add-fields').click(function() {
188
+ import_condition_fields();
 
 
 
 
 
 
 
189
  update_entries();
190
  return false;
191
  });
192
 
193
+ $('#overwrite-fields').click(function() {
194
+ clear_all_condition_fields();
195
+ import_condition_fields();
 
 
 
 
 
196
  update_entries();
 
197
  return false;
198
  });
199
 
200
+ $('#wpcf7cf-settings-text-clear').click(function() {
201
+ $('#wpcf7cf-settings-text-wrap').hide();
202
+ $('#wpcf7cf-settings-text').val('');
203
  return false;
204
  });
 
205
 
206
+ function update_entries() {
207
+ $if_values = $('.if-value');
208
+ init_autocomplete();
209
+ $if_values.css({'visibility':'visible'});
210
+ $if_values.autocomplete( "disable" );
211
+
212
+ $('#wpcf7cf-entries .wpcf7cf-and-rule').each(function() {
213
+ var $and_rule = $(this);
214
+ if ($and_rule.find('.operator').eq(0).val() === 'is empty' || $and_rule.find('.operator').eq(0).val() === 'not empty') {
215
+ $and_rule.find('.if-value').eq(0).css({'visibility':'hidden'});
216
+ } else if ($and_rule.find('.operator').eq(0).val().endsWith('(regex)')) {
217
+ $and_rule.find('.if-value').eq(0).autocomplete( "enable" );
218
+ }
219
+ });
220
 
221
+ scale_and_button();
 
 
222
 
223
+ set_events();
224
+ }
225
 
226
+ function init_autocomplete() {
227
+
228
+ $if_values.autocomplete({
229
+ disabled: true,
230
+ source: function(request, response) {
231
+ var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
232
+ response($.grep(regexes, function(value) {
233
+ return matcher.test(value.label || value.value || value) || matcher.test(value.desc);
234
+ }));
235
+ },
236
+ focus: function( event, ui ) {
237
+ $( event.target ).val( ui.item.desc );
238
+ return false;
239
+ },
240
+ select: function( event, ui ) {
241
+ $( event.target ).val( ui.item.desc );
242
+ return false;
243
+ },
244
+ open: function(e,ui) {
245
+ $el = $(e.target);
246
+ var styledTerm = termTemplate.replace('%s', $el.val());
247
+
248
+ $('.ui-autocomplete').find('em').each(function() {
249
+ var me = $(this);
250
+ me.html( me.text().replace($el.val(), styledTerm) );
251
+ });
252
+ },
253
+ minLength: 0
254
+ }).each(function() {
255
+ $(this).autocomplete( "instance" )._renderItem = function( ul, item ) {
256
+ return $("<li>")
257
+ .append("<div><em>" + item.label + "</em><br><em>" + item.desc + "</em></div>")
258
+ .appendTo(ul);
259
+ }
260
+ });
261
+ $if_values.on('focus', function() {
262
+ $(this).autocomplete("search");
263
+ });
264
+ }
265
 
266
+ update_entries();
267
+
268
+ function set_events() { // called at the end of update_entries
269
+
270
+ $('.wpcf7cf-and-rules').sortable();
271
+
272
+ $('.and-button').off('click').click(function() {
273
+ $this = $(this);
274
+ $andblock = $this.closest('.wpcf7cf-and-rule');
275
+ $andblocks_container = $this.closest('.wpcf7cf-and-rules');
276
+ next_index = $andblocks_container.data('next-index');
277
+ $andblocks_container.data('next-index',next_index+1);
278
+ var and_i = next_index;
279
+ clone_html = $andblock.get(0).outerHTML.replace(/wpcf7cf_options\[([0-9]*)\]\[and_rules\]\[([0-9]*)\]/g, 'wpcf7cf_options[$1][and_rules]['+and_i+']');
280
+ $andblock.after(clone_html);
281
+ update_entries();
282
+ return false;
283
+ });
284
+
285
+ $('.delete-button').off('click').click(function(){
286
+ $and_rule = $(this).closest('.wpcf7cf-and-rule');
287
+ if ($and_rule.siblings().length > 0) {
288
+ $and_rule.remove();
289
+ } else {
290
+ $and_rule[0].closest('.entry').remove();
291
+ }
292
+
293
+ update_entries();
294
+
295
+ return false;
296
+ });
297
+
298
+ $('.operator').off('change').change(function() {
299
+ update_entries();
300
+ return false;
301
+ });
302
+ }
303
+
304
+ function scale_and_button() {
305
+ $('.wpcf7cf-and-rule:first-child .and-button').each(function(){
306
+ $and_button = $(this);
307
+ num_and_rules = $and_button.closest('.wpcf7cf-and-rule').siblings().length+1;
308
+ var height = (34*num_and_rules-12)+'px';
309
+ $and_button.css({'height':height,'line-height':height});
310
  });
311
  }
312
 
313
+ // ------------------------------------
314
+ // OPTIONS PAGE
315
+ // ------------------------------------
316
+
317
+ $(document).ready(function() {
318
+
319
+ $('.wpcf7cf-options-notice .notice-dismiss-2').click(function () {
320
+ $('.wpcf7cf-options-notice .notice-dismiss').click();
321
+ });
322
+ $('.wpcf7cf-options-notice .notice-dismiss').click(function () {
323
+ wpcf7cf_dismiss_notice();
324
+ });
325
+
326
+ function wpcf7cf_dismiss_notice() {
327
+ $('input[name="wpcf7cf_options[notice_dismissed]"]').val('true');
328
+ $.post(ajaxurl, {action:'wpcf7cf_dismiss_notice'}, function(response) {
329
+ // nothing to do. dismiss_notice option should be set to TRUE server side by now.
330
+ });
331
+ }
332
+
333
+ });
334
+
335
+ })( jQuery );
336
 
337
+ }
readme.txt CHANGED
@@ -5,8 +5,8 @@ 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.9.8
9
- Stable tag: 1.4.1
10
  Requires PHP: 5.3
11
  License: GPLv2 or later
12
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -102,6 +102,16 @@ The conditional fields javascript code is loaded during wp_footer, so a call to
102
 
103
  == Changelog ==
104
 
 
 
 
 
 
 
 
 
 
 
105
  = 1.4.1 (08-21-18) =
106
  * Fixed some CSS issues (https://wordpress.org/support/topic/crash-view-admin-the-list-of-posts-entry/)
107
  * Dropped support for PHP version 5.2, now PHP 5.3+ is required to run the plugin. Let's push things forward!
5
  Website: http://bdwm.be
6
  Tags: wordpress, contact form 7, forms, conditional fields
7
  Requires at least: 4.1
8
+ Tested up to: 5.1.1
9
+ Stable tag: 1.4.2
10
  Requires PHP: 5.3
11
  License: GPLv2 or later
12
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
102
 
103
  == Changelog ==
104
 
105
+
106
+ = 1.4.2 (04-10-19) =
107
+ * Disabled mailbox syntax errors if there are group tags present. (this is overkill, and should be changed if the necassary hooks become available) https://wordpress.org/support/topic/filter-detect_invalid_mailbox_syntax/
108
+ * Checked issue: https://github.com/pwkip/contact-form-7-conditional-fields/issues/26 (nothing changed, but turns out to be working fine)
109
+ * Fixed issue where mail_2 added extra lines in the email message. https://github.com/pwkip/contact-form-7-conditional-fields/issues/30
110
+ * Made the clear_on_hide property a bit more useful (https://github.com/pwkip/contact-form-7-conditional-fields/issues/27)
111
+ * Got rid of warning in PHP 7 (https://wordpress.org/support/topic/compatibility-warning-message-regarding-wpcf7_admin_read_write_capability/)
112
+ * Fixed some javascript errors that appeared on non-CF7CF subpages of CF7
113
+ * Tested WP version 5.1.1
114
+
115
  = 1.4.1 (08-21-18) =
116
  * Fixed some CSS issues (https://wordpress.org/support/topic/crash-view-admin-the-list-of-posts-entry/)
117
  * Dropped support for PHP version 5.2, now PHP 5.3+ is required to run the plugin. Let's push things forward!
wpcf7cf-options.php CHANGED
@@ -16,6 +16,10 @@ $wpcf7cf_default_options = array(
16
  'notice_dismissed' => WPCF7CF_DEFAULT_NOTICE_DISMISSED
17
  );
18
 
 
 
 
 
19
  $wpcf7cf_default_options = apply_filters('wpcf7cf_default_options', $wpcf7cf_default_options);
20
 
21
  $wpcf7cf_options = get_option(WPCF7CF_OPTIONS);
@@ -52,10 +56,10 @@ function wpcf7cf_admin_add_page() {
52
  function wpcf7cf_options_page() {
53
  global $wpcf7cf_options;
54
 
55
- // Include in admin_enqueue_scripts action hook
56
- wp_enqueue_media();
57
- //wp_enqueue_script( 'custom-background' );
58
- wp_enqueue_script( 'wpcf7cf-image-upload', plugins_url('framework/js/bdwm-image-upload.js',__FILE__), array('jquery'), '1.0.0', true );
59
 
60
  if (isset($_POST['reset'])) {
61
  echo '<div id="message" class="updated fade"><p><strong>Settings restored to defaults</strong></p></div>';
16
  'notice_dismissed' => WPCF7CF_DEFAULT_NOTICE_DISMISSED
17
  );
18
 
19
+ if ( ! defined( 'WPCF7_ADMIN_READ_WRITE_CAPABILITY' ) ) {
20
+ define( 'WPCF7_ADMIN_READ_WRITE_CAPABILITY', 'publish_pages' );
21
+ }
22
+
23
  $wpcf7cf_default_options = apply_filters('wpcf7cf_default_options', $wpcf7cf_default_options);
24
 
25
  $wpcf7cf_options = get_option(WPCF7CF_OPTIONS);
56
  function wpcf7cf_options_page() {
57
  global $wpcf7cf_options;
58
 
59
+ // // Include in admin_enqueue_scripts action hook
60
+ // wp_enqueue_media();
61
+ // //wp_enqueue_script( 'custom-background' );
62
+ // wp_enqueue_script( 'wpcf7cf-image-upload', plugins_url('framework/js/bdwm-image-upload.js',__FILE__), array('jquery'), '1.0.0', true );
63
 
64
  if (isset($_POST['reset'])) {
65
  echo '<div id="message" class="updated fade"><p><strong>Settings restored to defaults</strong></p></div>';