Conditional Fields for Contact Form 7 - Version 0.1.3

Version Description

  • Removed fielset, id and class attributes for group tags, because they weren't used anyway and broke the shortcode
  • If extra attributes are added to the group shortcode, this will no longer break functionality (even though no attributes are supported)
Download this release

Release Info

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

Code changes from version 0.1.2 to 0.1.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.1.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.1.2' );
30
  define( 'WPCF7CF_REQUIRED_WP_VERSION', '4.1' );
31
  define( 'WPCF7CF_PLUGIN', __FILE__ );
32
  define( 'WPCF7CF_PLUGIN_BASENAME', plugin_basename( WPCF7CF_PLUGIN ) );
@@ -112,14 +112,12 @@ class ContactForm7ConditionalFields {
112
  $args = wp_parse_args( $args, array() );
113
  $type = 'group';
114
 
115
- $description = __( "Generate a group tag to group form elements that can be shown conditionally. For more details, see %s.", 'cf7cf' );
116
-
117
- $desc_link = wpcf7_link( __( 'http://bdwm.be/cf7cf', 'cf7cf' ), __( 'Group', 'cf7cf' ) );
118
 
119
  ?>
120
  <div class="control-box">
121
  <fieldset>
122
- <legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
123
 
124
  <table class="form-table">
125
  <tbody>
@@ -129,29 +127,6 @@ class ContactForm7ConditionalFields {
129
  <td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
130
  </tr>
131
 
132
- <tr>
133
- <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-style' ); ?>"><?php echo esc_html( __( 'Style', 'cf7cf' ) ); ?></label></th>
134
- <td>
135
- <fieldset>
136
- <legend class="screen-reader-text"><?php echo esc_html( __( 'Style', 'cf7cf' ) ); ?></legend>
137
- <select class="stylevalue oneline option" id="<?php echo esc_attr( $args['content'] . '-style' ); ?>">
138
- <option value="" selected="selected"><?php echo esc_html( __( 'None', 'cf7cf' ) ); ?></option>
139
- <option value="fieldset"><?php echo esc_html( __( 'Fieldset', 'cf7cf' ) ); ?></option>
140
- </select>
141
- </fieldset>
142
- <input type="hidden" name="style" id="<?php echo esc_attr( $args['content'] . '-style-hidden' ); ?>" class="stylevalue oneline option">
143
- </td>
144
- </tr>
145
-
146
- <tr>
147
- <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
148
- <td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
149
- </tr>
150
-
151
- <tr>
152
- <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
153
- <td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
154
- </tr>
155
  </tbody>
156
  </table>
157
  </fieldset>
@@ -177,7 +152,19 @@ add_filter( 'wpcf7_contact_form_properties', 'wpcf7cf_properties', 10, 2 );
177
  function wpcf7cf_properties($properties, $wpcf7form) {
178
  if (!is_admin()) { // TODO: kind of hacky. maybe find a better solution. Needed because otherwise the group tags will be replaced in the editor aswell.
179
  $form = $properties['form'];
180
- $form = preg_replace( '/\[group (.*?)\]/s', '<div id="$1" class="wpcf7cf_group">', $form );
 
 
 
 
 
 
 
 
 
 
 
 
181
  $form = preg_replace( '/\[\/group\]/s', '</div>', $form );
182
 
183
  $properties['form'] = $form;
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.1.3
8
  Author URI: http://bdwm.be/
9
  */
10
 
26
  ?>
27
  <?php
28
 
29
+ define( 'WPCF7CF_VERSION', '0.1.3' );
30
  define( 'WPCF7CF_REQUIRED_WP_VERSION', '4.1' );
31
  define( 'WPCF7CF_PLUGIN', __FILE__ );
32
  define( 'WPCF7CF_PLUGIN_BASENAME', plugin_basename( WPCF7CF_PLUGIN ) );
112
  $args = wp_parse_args( $args, array() );
113
  $type = 'group';
114
 
115
+ $description = __( "Generate a group tag to group form elements that can be shown conditionally.", 'cf7cf' );
 
 
116
 
117
  ?>
118
  <div class="control-box">
119
  <fieldset>
120
+ <legend><?php echo sprintf( esc_html( $description ) ); ?></legend>
121
 
122
  <table class="form-table">
123
  <tbody>
127
  <td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
128
  </tr>
129
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  </tbody>
131
  </table>
132
  </fieldset>
152
  function wpcf7cf_properties($properties, $wpcf7form) {
153
  if (!is_admin()) { // TODO: kind of hacky. maybe find a better solution. Needed because otherwise the group tags will be replaced in the editor aswell.
154
  $form = $properties['form'];
155
+
156
+ $find = array(
157
+ '/\[group\s(.*?)\s.*?class:([^\s:\]]*).*?\]/s', // match the class
158
+ // remove all other junk
159
+ '/\[group\s([^\s\]]*)\s?(.*?)\]/s'
160
+ );
161
+
162
+ $replace = array(
163
+ '[group $1 class="$2"]',
164
+ '<div id="$1" data-class="wpcf7cf_group" $2>'
165
+ );
166
+
167
+ $form = preg_replace( $find, $replace, $form );
168
  $form = preg_replace( '/\[\/group\]/s', '</div>', $form );
169
 
170
  $properties['form'] = $form;
js/scripts.js CHANGED
@@ -4,7 +4,7 @@
4
 
5
  $(document).ready(function() {
6
  function display_fields() {
7
- $('.wpcf7cf_group').hide();
8
  for (var i=0; i < wpcf7cf_options.length; i++) {
9
 
10
  var condition = wpcf7cf_options[i];
4
 
5
  $(document).ready(function() {
6
  function display_fields() {
7
+ $('[data-class=wpcf7cf_group]').hide();
8
  for (var i=0; i < wpcf7cf_options.length; i++) {
9
 
10
  var condition = wpcf7cf_options[i];
readme.txt CHANGED
@@ -5,11 +5,11 @@ Website: http://bdwm.be
5
  Tags: wordpress, contact form 7, forms, conditional fields
6
  Requires at least: 3.6.1
7
  Tested up to: 4.5.2
8
- Stable tag: 0.1.2
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
12
- Adds support for conditional fields to Contact Form 7.
13
 
14
  == Description ==
15
 
@@ -19,6 +19,8 @@ If you edit your CF7 form, you will see an additional tag called "Conditional fi
19
  After you added the field group(s), you should click Save.
20
  Then you should go to the "Conditional fields" tab to create one or more conditions that will make the group(s) appear.
21
 
 
 
22
  == Installation ==
23
 
24
  Please follow the [standard installation procedure for WordPress plugins](http://codex.wordpress.org/Managing_Plugins#Installing_Plugins).
@@ -36,15 +38,22 @@ Because no questions have been asked frequently about this plugin.
36
 
37
  == Changelog ==
38
 
39
- = 0.1 =
40
 
41
- First release
 
 
 
 
 
 
42
 
43
  = 0.1.1 =
44
 
45
  Fixed bug with exclusive checkboxes (https://wordpress.org/support/topic/groups-not-showing)
46
 
47
- = 0.1.2 =
 
 
 
48
 
49
- * Make code work with select element that allows multiple options.
50
- * Only load javascript on pages that contain a CF7 form
5
  Tags: wordpress, contact form 7, forms, conditional fields
6
  Requires at least: 3.6.1
7
  Tested up to: 4.5.2
8
+ Stable tag: 0.1.3
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
12
+ Adds conditional logic to Contact Form 7.
13
 
14
  == Description ==
15
 
19
  After you added the field group(s), you should click Save.
20
  Then you should go to the "Conditional fields" tab to create one or more conditions that will make the group(s) appear.
21
 
22
+ A detailed example of how to use the plugin can be found here: [http://bdwm.be/wpcf7cf/how-to-set-up-conditional-fields-for-contact-form-7/](http://bdwm.be/wpcf7cf/how-to-set-up-conditional-fields-for-contact-form-7/)
23
+
24
  == Installation ==
25
 
26
  Please follow the [standard installation procedure for WordPress plugins](http://codex.wordpress.org/Managing_Plugins#Installing_Plugins).
38
 
39
  == Changelog ==
40
 
41
+ = 0.1.3 =
42
 
43
+ * Removed fielset, id and class attributes for group tags, because they weren't used anyway and broke the shortcode
44
+ * If extra attributes are added to the group shortcode, this will no longer break functionality (even though no attributes are supported)
45
+
46
+ = 0.1.2 =
47
+
48
+ * Make code work with select element that allows multiple options.
49
+ * Only load javascript on pages that contain a CF7 form
50
 
51
  = 0.1.1 =
52
 
53
  Fixed bug with exclusive checkboxes (https://wordpress.org/support/topic/groups-not-showing)
54
 
55
+ = 0.1 =
56
+
57
+ First release
58
+
59