Conditional Fields for Contact Form 7 - Version 0.2.7

Version Description

  • Added support for conditional fields in the email (2) field
  • Got rid of some PHP warnings
  • Saving a form only once, directly after adding or removing conditions, caused conditional logic not to work. This is fixed now. Thanks to @cpaprotna for pointing me in the right direction. (https://wordpress.org/support/topic/no-more-than-3-conditional-statements/)
  • Fix validation error with hidden checkbox groups (https://wordpress.org/support/topic/hidden-group-required-field-is-showing-error/)
Download this release

Release Info

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

Code changes from version 0.2.6 to 0.2.7

Files changed (4) hide show
  1. admin.php +7 -3
  2. contact-form-7-conditional-fields.php +32 -2
  3. readme.txt +7 -1
  4. style.css +1 -0
admin.php CHANGED
@@ -21,7 +21,7 @@ function add_conditional_panel($panels) {
21
  }
22
 
23
  function all_field_options($post, $selected = '-1') {
24
- $all_fields = $post->form_scan_shortcode();
25
  ?>
26
  <option value="-1" <?php echo $selected == '-1'?'selected':'' ?>>-- Select field --</option>
27
  <?php
@@ -34,7 +34,7 @@ function all_field_options($post, $selected = '-1') {
34
  }
35
 
36
  function all_group_options($post, $selected = '-1') {
37
- $all_groups = $post->form_scan_shortcode(array('type'=>'group'));
38
 
39
  ?>
40
  <option value="-1" <?php echo $selected == '-1'?'selected':'' ?>>-- Select group --</option>
@@ -186,7 +186,11 @@ function wpcf7cf_save_contact_form( $contact_form )
186
 
187
  unset($_POST['wpcf7cf_options']['{id}']); // remove the dummy entry
188
 
189
- update_post_meta( $post_id, 'wpcf7cf_options', $_POST['wpcf7cf_options'] );
 
 
 
 
190
 
191
  };
192
 
21
  }
22
 
23
  function all_field_options($post, $selected = '-1') {
24
+ $all_fields = $post->scan_form_tags();
25
  ?>
26
  <option value="-1" <?php echo $selected == '-1'?'selected':'' ?>>-- Select field --</option>
27
  <?php
34
  }
35
 
36
  function all_group_options($post, $selected = '-1') {
37
+ $all_groups = $post->scan_form_tags(array('type'=>'group'));
38
 
39
  ?>
40
  <option value="-1" <?php echo $selected == '-1'?'selected':'' ?>>-- Select group --</option>
186
 
187
  unset($_POST['wpcf7cf_options']['{id}']); // remove the dummy entry
188
 
189
+ $options = array_values($_POST['wpcf7cf_options']);
190
+
191
+ update_post_meta( $post_id, 'wpcf7cf_options', $options );
192
+
193
+ return;
194
 
195
  };
196
 
contact-form-7-conditional-fields.php CHANGED
@@ -64,6 +64,9 @@ class ContactForm7ConditionalFields {
64
 
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
 
@@ -97,7 +100,8 @@ class ContactForm7ConditionalFields {
97
  }
98
 
99
  function shortcode_handler($tag) {
100
- $tag = new WPCF7_Shortcode($tag);
 
101
  //ob_start();
102
  //print_r($tag);
103
  //return print_r($tag, true);
@@ -210,7 +214,13 @@ class ContactForm7ConditionalFields {
210
  $posted_data = WPCF7_Submission::get_instance()->get_posted_data();
211
  }
212
 
213
- $this->hidden_fields = json_decode(stripslashes($posted_data['_wpcf7cf_hidden_group_fields']));
 
 
 
 
 
 
214
  $this->hidden_groups = json_decode(stripslashes($posted_data['_wpcf7cf_hidden_groups']));
215
  $this->visible_groups = json_decode(stripslashes($posted_data['_wpcf7cf_visible_groups']));
216
  }
@@ -228,6 +238,19 @@ class ContactForm7ConditionalFields {
228
  return $components;
229
  }
230
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
  function hide_hidden_mail_fields_regex_callback ( $matches ) {
232
  $name = $matches[1];
233
  $content = $matches[2];
@@ -318,3 +341,10 @@ add_action('wpcf7_form_hidden_fields', 'wpcf7cf_form_hidden_fields',10,1);
318
  function wpcf7cf_form_hidden_fields($hidden_fields) {
319
  return array('_wpcf7cf_hidden_group_fields' => '', '_wpcf7cf_hidden_groups' => '', '_wpcf7cf_visible_groups' => '');
320
  }
 
 
 
 
 
 
 
64
 
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
+ add_filter('wpcf7_additional_mail', array($this, 'hide_hidden_mail_fields_additional_mail'), 10, 2);
68
+
69
+ //apply_filters( 'wpcf7_additional_mail',$additional_mail, $contact_form )
70
 
71
  add_filter( 'wpcf7_validate', array($this, 'skip_validation_for_hidden_fields'), 2, 2 );
72
 
100
  }
101
 
102
  function shortcode_handler($tag) {
103
+ //$tag = new WPCF7_Shortcode($tag);
104
+ $tag = new WPCF7_FormTag($tag);
105
  //ob_start();
106
  //print_r($tag);
107
  //return print_r($tag, true);
214
  $posted_data = WPCF7_Submission::get_instance()->get_posted_data();
215
  }
216
 
217
+ $hidden_fields = json_decode(stripslashes($posted_data['_wpcf7cf_hidden_group_fields']));
218
+ foreach ($hidden_fields as $field) {
219
+ $this->hidden_fields[] = $field;
220
+ if (wpcf7cf_endswith($field, '[]')) {
221
+ $this->hidden_fields[] = substr($field,0,strlen($field)-2);
222
+ }
223
+ }
224
  $this->hidden_groups = json_decode(stripslashes($posted_data['_wpcf7cf_hidden_groups']));
225
  $this->visible_groups = json_decode(stripslashes($posted_data['_wpcf7cf_visible_groups']));
226
  }
238
  return $components;
239
  }
240
 
241
+ function hide_hidden_mail_fields_additional_mail($additional_mail, $contact_form) {;
242
+
243
+ $regex = '@\[[\t ]*([a-zA-Z_][0-9a-zA-Z:._-]*)[\t ]*\](.*?)\[[\t ]*/[\t ]*\1[\t ]*\]@s';
244
+
245
+ $additional_mail['mail_2']['body'] = preg_replace_callback($regex, array($this, 'hide_hidden_mail_fields_regex_callback'), $additional_mail['mail_2']['body'] );
246
+ $additional_mail['mail_2']['subject'] = preg_replace_callback($regex, array($this, 'hide_hidden_mail_fields_regex_callback'), $additional_mail['mail_2']['subject'] );
247
+ $additional_mail['mail_2']['sender'] = preg_replace_callback($regex, array($this, 'hide_hidden_mail_fields_regex_callback'), $additional_mail['mail_2']['sender'] );
248
+ $additional_mail['mail_2']['recipient'] = preg_replace_callback($regex, array($this, 'hide_hidden_mail_fields_regex_callback'), $additional_mail['mail_2']['recipient'] );
249
+ $additional_mail['mail_2']['additional_headers'] = preg_replace_callback($regex, array($this, 'hide_hidden_mail_fields_regex_callback'), $additional_mail['mail_2']['additional_headers'] );
250
+
251
+ return $additional_mail;
252
+ }
253
+
254
  function hide_hidden_mail_fields_regex_callback ( $matches ) {
255
  $name = $matches[1];
256
  $content = $matches[2];
341
  function wpcf7cf_form_hidden_fields($hidden_fields) {
342
  return array('_wpcf7cf_hidden_group_fields' => '', '_wpcf7cf_hidden_groups' => '', '_wpcf7cf_visible_groups' => '');
343
  }
344
+
345
+ function wpcf7cf_endswith($string, $test) {
346
+ $strlen = strlen($string);
347
+ $testlen = strlen($test);
348
+ if ($testlen > $strlen) return false;
349
+ return substr_compare($string, $test, $strlen - $testlen, $testlen) === 0;
350
+ }
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.6
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
@@ -47,6 +47,12 @@ Because no questions have been asked frequently about this plugin.
47
 
48
  == Changelog ==
49
 
 
 
 
 
 
 
50
  = 0.2.6 =
51
  * Fixed problems with exclusive checkboxes in IE (https://wordpress.org/support/topic/internet-explorer-conditional-exclusive-checkboxes/)
52
 
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.7
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.7 =
51
+ * Added support for conditional fields in the email (2) field
52
+ * Got rid of some PHP warnings
53
+ * Saving a form only once, directly after adding or removing conditions, caused conditional logic not to work. This is fixed now. Thanks to @cpaprotna for pointing me in the right direction. (https://wordpress.org/support/topic/no-more-than-3-conditional-statements/)
54
+ * Fix validation error with hidden checkbox groups (https://wordpress.org/support/topic/hidden-group-required-field-is-showing-error/)
55
+
56
  = 0.2.6 =
57
  * Fixed problems with exclusive checkboxes in IE (https://wordpress.org/support/topic/internet-explorer-conditional-exclusive-checkboxes/)
58
 
style.css CHANGED
@@ -0,0 +1 @@
 
1
+ /**/