Version Description
- Added import feature
- Added support for nested groups in email
- Tested on WP version 4.7.2 with Contact Form 7 version 4.6.1
Download this release
Release Info
Developer | Jules Colle |
Plugin | Conditional Fields for Contact Form 7 |
Version | 1.1 |
Comparing to | |
See all releases |
Code changes from version 1.0 to 1.1
- admin.php +59 -17
- contact-form-7-conditional-fields.php +6 -17
- readme.txt +7 -2
admin.php
CHANGED
@@ -100,15 +100,24 @@ function wpcf7cf_editor_panel_conditional($form) {
|
|
100 |
|
101 |
|
102 |
<div id="wpcf7cf-text-entries">
|
103 |
-
<p><a href="#" id="wpcf7cf-settings-to-text">
|
104 |
<div id="wpcf7cf-settings-text-wrap">
|
105 |
<textarea id="wpcf7cf-settings-text"></textarea>
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
<p><a href="#" id="wpcf7cf-settings-text-clear">Clear</a></p>
|
|
|
107 |
</div>
|
108 |
</div>
|
|
|
109 |
|
110 |
<script>
|
111 |
(function($) {
|
|
|
112 |
var index = $('#wpcf7cf-entries .entry').length;
|
113 |
|
114 |
$('.delete-button').click(function(){
|
@@ -121,31 +130,53 @@ function wpcf7cf_editor_panel_conditional($form) {
|
|
121 |
|
122 |
$('#wpcf7cf-add-button').click(function(){
|
123 |
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
// return false;
|
128 |
-
// } else if($('#wpcf7cf-new-entry .if-field-select').val() == $('#wpcf7cf-new-entry .then-field-select').val()) {
|
129 |
-
// alert('The fields cannot be the same');
|
130 |
-
// $(this).parent().remove();
|
131 |
-
// return false;
|
132 |
-
// }
|
133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
var $delete_button = $('#wpcf7cf-delete-button').clone().removeAttr('id');
|
135 |
$('<div class="entry" id="entry-'+index+'">'+($('#wpcf7cf-new-entry').html().replace(/{id}/g, index))+'</div>').prependTo('#wpcf7cf-entries').append($delete_button);
|
136 |
$delete_button.click(function(){
|
137 |
-
|
138 |
-
//if (confirm('You sure?')===false) return false;
|
139 |
$(this).parent().remove();
|
140 |
return false;
|
141 |
-
|
142 |
});
|
143 |
index++;
|
144 |
-
return false;
|
145 |
-
|
146 |
-
});
|
147 |
|
148 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
|
150 |
$('#wpcf7cf-settings-text-wrap').hide();
|
151 |
|
@@ -164,6 +195,17 @@ function wpcf7cf_editor_panel_conditional($form) {
|
|
164 |
return false;
|
165 |
});
|
166 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
$('#wpcf7cf-settings-text-clear').click(function() {
|
168 |
$('#wpcf7cf-settings-text-wrap').hide();
|
169 |
$('#wpcf7cf-settings-text').val('');
|
100 |
|
101 |
|
102 |
<div id="wpcf7cf-text-entries">
|
103 |
+
<p><a href="#" id="wpcf7cf-settings-to-text">import/export</a></p>
|
104 |
<div id="wpcf7cf-settings-text-wrap">
|
105 |
<textarea id="wpcf7cf-settings-text"></textarea>
|
106 |
+
<br>
|
107 |
+
Import actions (Beta feature!):
|
108 |
+
<input type="button" value="Add conditions" id="add-fields" >
|
109 |
+
<input type="button" value="Overwrite conditions" id="overwrite-fields" >
|
110 |
+
<span style="color:red"><b>WARNING</b>: If you screw something up, just reload the page without saving. If you click <em>save</em> after screwing up, you're screwed.</span>
|
111 |
+
|
112 |
<p><a href="#" id="wpcf7cf-settings-text-clear">Clear</a></p>
|
113 |
+
|
114 |
</div>
|
115 |
</div>
|
116 |
+
|
117 |
|
118 |
<script>
|
119 |
(function($) {
|
120 |
+
|
121 |
var index = $('#wpcf7cf-entries .entry').length;
|
122 |
|
123 |
$('.delete-button').click(function(){
|
130 |
|
131 |
$('#wpcf7cf-add-button').click(function(){
|
132 |
|
133 |
+
var id = add_condition_fields();
|
134 |
+
|
135 |
+
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
|
137 |
+
});
|
138 |
+
|
139 |
+
function clear_all_condition_fields() {
|
140 |
+
$('.entry').remove();
|
141 |
+
}
|
142 |
+
|
143 |
+
function add_condition_fields() {
|
144 |
var $delete_button = $('#wpcf7cf-delete-button').clone().removeAttr('id');
|
145 |
$('<div class="entry" id="entry-'+index+'">'+($('#wpcf7cf-new-entry').html().replace(/{id}/g, index))+'</div>').prependTo('#wpcf7cf-entries').append($delete_button);
|
146 |
$delete_button.click(function(){
|
|
|
|
|
147 |
$(this).parent().remove();
|
148 |
return false;
|
|
|
149 |
});
|
150 |
index++;
|
|
|
|
|
|
|
151 |
|
152 |
+
return (index-1);
|
153 |
+
}
|
154 |
+
|
155 |
+
function import_condition_fields() {
|
156 |
+
var lines = $('#wpcf7cf-settings-text').val().split(/\r?\n/);
|
157 |
+
console.log(lines);
|
158 |
+
for (var i = lines.length+1; i>-1; i--) {
|
159 |
+
|
160 |
+
var str = lines[i];
|
161 |
+
|
162 |
+
var match = regex.exec(str);
|
163 |
+
|
164 |
+
if (match == null) continue;
|
165 |
+
|
166 |
+
console.log(match[1]+' '+match[2]+' '+match[3]+' '+match[4]);
|
167 |
+
|
168 |
+
var id = add_condition_fields();
|
169 |
+
|
170 |
+
$('#entry-'+id+' .if-field-select').val(match[1]);
|
171 |
+
$('#entry-'+id+' .operator').val(match[2]);
|
172 |
+
$('#entry-'+id+' .if-value').val(match[3]);
|
173 |
+
$('#entry-'+id+' .then-field-select').val(match[4]);
|
174 |
+
|
175 |
+
regex.lastIndex = 0;
|
176 |
+
}
|
177 |
+
}
|
178 |
+
|
179 |
+
// export/import settings
|
180 |
|
181 |
$('#wpcf7cf-settings-text-wrap').hide();
|
182 |
|
195 |
return false;
|
196 |
});
|
197 |
|
198 |
+
var regex = /if \[(.*)] (.*equals) "(.*)" then show \[(.*)]/g;
|
199 |
+
|
200 |
+
$('#add-fields').click(function() {
|
201 |
+
import_condition_fields();
|
202 |
+
});
|
203 |
+
|
204 |
+
$('#overwrite-fields').click(function() {
|
205 |
+
clear_all_condition_fields();
|
206 |
+
import_condition_fields();
|
207 |
+
});
|
208 |
+
|
209 |
$('#wpcf7cf-settings-text-clear').click(function() {
|
210 |
$('#wpcf7cf-settings-text-wrap').hide();
|
211 |
$('#wpcf7cf-settings-text').val('');
|
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.
|
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', '1.
|
30 |
define( 'WPCF7CF_REQUIRED_WP_VERSION', '4.1' );
|
31 |
define( 'WPCF7CF_PLUGIN', __FILE__ );
|
32 |
define( 'WPCF7CF_PLUGIN_BASENAME', plugin_basename( WPCF7CF_PLUGIN ) );
|
@@ -270,22 +270,11 @@ class ContactForm7ConditionalFields {
|
|
270 |
return '';
|
271 |
} elseif ( in_array( $name, $this->visible_groups ) ) {
|
272 |
// The tag name represents a visible group, so remove the tags themselves, but return everything else
|
273 |
-
return $content;
|
274 |
-
|
275 |
-
// The tag name doesn't represent a group that was used in the form. Leave it alone (return the entire match).
|
276 |
-
return $matches[0];
|
277 |
-
}
|
278 |
-
}
|
279 |
|
280 |
-
|
281 |
-
|
282 |
-
$content = $matches[2];
|
283 |
-
if ( in_array( $name, $this->hidden_groups ) ) {
|
284 |
-
// The tag name represents a hidden group, so replace everything from [tagname] to [/tagname] with nothing
|
285 |
-
return '';
|
286 |
-
} elseif ( in_array( $name, $this->visible_groups ) ) {
|
287 |
-
// The tag name represents a visible group, so remove the tags themselves, but return everything else
|
288 |
-
return $content;
|
289 |
} else {
|
290 |
// The tag name doesn't represent a group that was used in the form. Leave it alone (return the entire match).
|
291 |
return $matches[0];
|
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.1
|
8 |
Author URI: http://bdwm.be/
|
9 |
*/
|
10 |
|
26 |
?>
|
27 |
<?php
|
28 |
|
29 |
+
define( 'WPCF7CF_VERSION', '1.1' );
|
30 |
define( 'WPCF7CF_REQUIRED_WP_VERSION', '4.1' );
|
31 |
define( 'WPCF7CF_PLUGIN', __FILE__ );
|
32 |
define( 'WPCF7CF_PLUGIN_BASENAME', plugin_basename( WPCF7CF_PLUGIN ) );
|
270 |
return '';
|
271 |
} elseif ( in_array( $name, $this->visible_groups ) ) {
|
272 |
// The tag name represents a visible group, so remove the tags themselves, but return everything else
|
273 |
+
//return $content;
|
274 |
+
$regex = '@\[[\t ]*([a-zA-Z_][0-9a-zA-Z:._-]*)[\t ]*\](.*?)\[[\t ]*/[\t ]*\1[\t ]*\]@s';
|
|
|
|
|
|
|
|
|
275 |
|
276 |
+
// instead of just returning the $content, return the preg_replaced content :)
|
277 |
+
return preg_replace_callback($regex, array($this, 'hide_hidden_mail_fields_regex_callback'), $content );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
278 |
} else {
|
279 |
// The tag name doesn't represent a group that was used in the form. Leave it alone (return the entire match).
|
280 |
return $matches[0];
|
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.7.
|
9 |
-
Stable tag: 1.
|
10 |
License: GPLv2 or later
|
11 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
12 |
|
@@ -47,6 +47,11 @@ Because no questions have been asked frequently about this plugin.
|
|
47 |
|
48 |
== Changelog ==
|
49 |
|
|
|
|
|
|
|
|
|
|
|
50 |
= 1.0 =
|
51 |
* I feel that at this point the plugin is stable enough in most cases, so it's about time to take it out of beta :)
|
52 |
* Update JS en CSS version numbers
|
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.7.2
|
9 |
+
Stable tag: 1.1
|
10 |
License: GPLv2 or later
|
11 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
12 |
|
47 |
|
48 |
== Changelog ==
|
49 |
|
50 |
+
= 1.1 =
|
51 |
+
* Added import feature
|
52 |
+
* Added support for nested groups in email
|
53 |
+
* Tested on WP version 4.7.2 with Contact Form 7 version 4.6.1
|
54 |
+
|
55 |
= 1.0 =
|
56 |
* I feel that at this point the plugin is stable enough in most cases, so it's about time to take it out of beta :)
|
57 |
* Update JS en CSS version numbers
|