Version Description
- Fixed small bug with integration with Contact Form 7 Multi-Step Forms
- Also trigger hiding/showing of groups while typing or pasting text in input fields
- Added support for input type="reset"
- Added animations
- Added settings page to wp-admin: Contact > Conditional Fields
Download this release
Release Info
Developer | Jules Colle |
Plugin | Conditional Fields for Contact Form 7 |
Version | 1.3 |
Comparing to | |
See all releases |
Code changes from version 1.2.3 to 1.3
- admin-style.css +29 -0
- cf7cf.php +9 -8
- contact-form-7-conditional-fields.php +5 -4
- js/scripts.js +53 -16
- js/scripts_admin.js +18 -0
- options.php +308 -0
- readme.txt +8 -1
- style.css +4 -1
admin-style.css
CHANGED
@@ -3,3 +3,32 @@
|
|
3 |
#wpcf7cf-new-entry { display: inline-block; display:none; }
|
4 |
#wpcf7cf-delete-button { display: none; }
|
5 |
#wpcf7cf-settings-text { width: 100%; height: 280px; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
#wpcf7cf-new-entry { display: inline-block; display:none; }
|
4 |
#wpcf7cf-delete-button { display: none; }
|
5 |
#wpcf7cf-settings-text { width: 100%; height: 280px; }
|
6 |
+
|
7 |
+
.wpcf7cf-admin-wrap .label, .wpcf7cf-admin-wrap .field, .wpcf7cf-admin-wrap .description {
|
8 |
+
padding: 10px;
|
9 |
+
display: inline-block;
|
10 |
+
vertical-align: middle;
|
11 |
+
width: 10%;
|
12 |
+
}
|
13 |
+
.wpcf7cf-admin-wrap .field {
|
14 |
+
width: 20%;
|
15 |
+
}
|
16 |
+
.wpcf7cf-admin-wrap .description {
|
17 |
+
width: 40%;
|
18 |
+
vertical-align: top;
|
19 |
+
|
20 |
+
}
|
21 |
+
|
22 |
+
.wpcf7cf-admin-wrap .option-line {
|
23 |
+
border-bottom: 1px solid #dddddd;
|
24 |
+
background-color: #f9f9f9;
|
25 |
+
padding: 0 10px;
|
26 |
+
}
|
27 |
+
|
28 |
+
.wpcf7cf-admin-wrap .option-line:nth-child(2n) {
|
29 |
+
background-color: #e9e9e9;
|
30 |
+
}
|
31 |
+
|
32 |
+
.wpcf7cf-admin-wrap .option-line input, .wpcf7cf-admin-wrap .option-line select {
|
33 |
+
width: 100%;
|
34 |
+
}
|
cf7cf.php
CHANGED
@@ -171,7 +171,7 @@ class ContactForm7ConditionalFields {
|
|
171 |
|
172 |
function cf7msm_merge_post_with_cookie($posted_data) {
|
173 |
|
174 |
-
if (!function_exists('cf7msm_get')) return $posted_data;
|
175 |
|
176 |
if (!$posted_data) {
|
177 |
$posted_data = WPCF7_Submission::get_instance()->get_posted_data();
|
@@ -306,31 +306,32 @@ function wpcf7cf_properties($properties, $wpcf7form) {
|
|
306 |
return $properties;
|
307 |
}
|
308 |
|
309 |
-
$
|
310 |
|
311 |
add_action('wpcf7_contact_form', 'wpcf7cf_enqueue_scripts', 10, 1);
|
312 |
function wpcf7cf_enqueue_scripts(WPCF7_ContactForm $cf7form) {
|
313 |
|
314 |
if (is_admin()) return;
|
315 |
|
316 |
-
global $
|
317 |
-
$
|
318 |
|
319 |
if ( in_the_loop() ) {
|
320 |
$post_id = empty($post->ID) ? '0' : $post->ID;
|
321 |
-
$unit_tag = 'wpcf7-f'.$cf7form->id().'-p'.$post_id.'-o'.$
|
322 |
} else {
|
323 |
-
$unit_tag = 'wpcf7-f'.$cf7form->id().'-o'.$
|
324 |
}
|
325 |
|
326 |
$options = array(
|
327 |
'form_id' => $cf7form->id(),
|
328 |
'unit_tag' => $unit_tag,
|
329 |
'conditions' => get_post_meta($cf7form->id(),'wpcf7cf_options', true),
|
|
|
330 |
);
|
331 |
|
332 |
-
wp_enqueue_script('
|
333 |
-
wp_localize_script('
|
334 |
}
|
335 |
|
336 |
add_action('wpcf7_form_hidden_fields', 'wpcf7cf_form_hidden_fields',10,1);
|
171 |
|
172 |
function cf7msm_merge_post_with_cookie($posted_data) {
|
173 |
|
174 |
+
if (!function_exists('cf7msm_get') || !key_exists('cf7msm_posted_data',$_COOKIE)) return $posted_data;
|
175 |
|
176 |
if (!$posted_data) {
|
177 |
$posted_data = WPCF7_Submission::get_instance()->get_posted_data();
|
306 |
return $properties;
|
307 |
}
|
308 |
|
309 |
+
$wpcf7cf_global_count = 0;
|
310 |
|
311 |
add_action('wpcf7_contact_form', 'wpcf7cf_enqueue_scripts', 10, 1);
|
312 |
function wpcf7cf_enqueue_scripts(WPCF7_ContactForm $cf7form) {
|
313 |
|
314 |
if (is_admin()) return;
|
315 |
|
316 |
+
global $wpcf7cf_global_count, $post;
|
317 |
+
$wpcf7cf_global_count++;
|
318 |
|
319 |
if ( in_the_loop() ) {
|
320 |
$post_id = empty($post->ID) ? '0' : $post->ID;
|
321 |
+
$unit_tag = 'wpcf7-f'.$cf7form->id().'-p'.$post_id.'-o'.$wpcf7cf_global_count;
|
322 |
} else {
|
323 |
+
$unit_tag = 'wpcf7-f'.$cf7form->id().'-o'.$wpcf7cf_global_count;
|
324 |
}
|
325 |
|
326 |
$options = array(
|
327 |
'form_id' => $cf7form->id(),
|
328 |
'unit_tag' => $unit_tag,
|
329 |
'conditions' => get_post_meta($cf7form->id(),'wpcf7cf_options', true),
|
330 |
+
'settings' => get_option(WPCF7CF_OPTIONS)
|
331 |
);
|
332 |
|
333 |
+
wp_enqueue_script('wpcf7cf-scripts', plugins_url('js/scripts.js', __FILE__), array('jquery'), WPCF7CF_VERSION, true);
|
334 |
+
wp_localize_script('wpcf7cf-scripts', 'wpcf7cf_options_'.$wpcf7cf_global_count, $options);
|
335 |
}
|
336 |
|
337 |
add_action('wpcf7_form_hidden_fields', 'wpcf7cf_form_hidden_fields',10,1);
|
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 |
|
@@ -24,7 +24,7 @@ Author URI: http://bdwm.be/
|
|
24 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
25 |
*/
|
26 |
|
27 |
-
if (!defined('WPCF7CF_VERSION')) define( 'WPCF7CF_VERSION', '1.
|
28 |
if (!defined('WPCF7CF_REQUIRED_WP_VERSION')) define( 'WPCF7CF_REQUIRED_WP_VERSION', '4.1' );
|
29 |
if (!defined('WPCF7CF_PLUGIN')) define( 'WPCF7CF_PLUGIN', __FILE__ );
|
30 |
if (!defined('WPCF7CF_PLUGIN_BASENAME')) define( 'WPCF7CF_PLUGIN_BASENAME', plugin_basename( WPCF7CF_PLUGIN ) );
|
@@ -43,8 +43,6 @@ function wpcf7cf_plugin_url( $path = '' ) {
|
|
43 |
return $url;
|
44 |
}
|
45 |
|
46 |
-
require_once 'cf7cf.php';
|
47 |
-
|
48 |
if(file_exists(WPCF7CF_PLUGIN_DIR.'/pro-functions.php')) {
|
49 |
if (!defined('WPCF7CF_IS_PRO')) define( 'WPCF7CF_IS_PRO', true );
|
50 |
require_once 'pro-functions.php';
|
@@ -52,3 +50,6 @@ if(file_exists(WPCF7CF_PLUGIN_DIR.'/pro-functions.php')) {
|
|
52 |
if (!defined('WPCF7CF_IS_PRO')) define( 'WPCF7CF_IS_PRO', false );
|
53 |
}
|
54 |
|
|
|
|
|
|
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.3
|
8 |
Author URI: http://bdwm.be/
|
9 |
*/
|
10 |
|
24 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
25 |
*/
|
26 |
|
27 |
+
if (!defined('WPCF7CF_VERSION')) define( 'WPCF7CF_VERSION', '1.3' );
|
28 |
if (!defined('WPCF7CF_REQUIRED_WP_VERSION')) define( 'WPCF7CF_REQUIRED_WP_VERSION', '4.1' );
|
29 |
if (!defined('WPCF7CF_PLUGIN')) define( 'WPCF7CF_PLUGIN', __FILE__ );
|
30 |
if (!defined('WPCF7CF_PLUGIN_BASENAME')) define( 'WPCF7CF_PLUGIN_BASENAME', plugin_basename( WPCF7CF_PLUGIN ) );
|
43 |
return $url;
|
44 |
}
|
45 |
|
|
|
|
|
46 |
if(file_exists(WPCF7CF_PLUGIN_DIR.'/pro-functions.php')) {
|
47 |
if (!defined('WPCF7CF_IS_PRO')) define( 'WPCF7CF_IS_PRO', true );
|
48 |
require_once 'pro-functions.php';
|
50 |
if (!defined('WPCF7CF_IS_PRO')) define( 'WPCF7CF_IS_PRO', false );
|
51 |
}
|
52 |
|
53 |
+
require_once 'cf7cf.php';
|
54 |
+
require_once 'options.php';
|
55 |
+
|
js/scripts.js
CHANGED
@@ -14,7 +14,9 @@ var cf7signature_resized = 0; // for compatibility with contact-form-7-signature
|
|
14 |
}
|
15 |
|
16 |
$(document).ready(function() {
|
17 |
-
function display_fields(unit_tag, wpcf7cf_conditions) {
|
|
|
|
|
18 |
|
19 |
//for compatibility with contact-form-7-signature-addon
|
20 |
if (cf7signature_resized == 0 && typeof signatures !== 'undefined' && signatures.constructor === Array && signatures.length > 0 ) {
|
@@ -29,7 +31,8 @@ var cf7signature_resized = 0; // for compatibility with contact-form-7-signature
|
|
29 |
}
|
30 |
}
|
31 |
|
32 |
-
$("#"+unit_tag+" [data-class='wpcf7cf_group']").
|
|
|
33 |
for (var i=0; i < wpcf7cf_conditions.length; i++) {
|
34 |
|
35 |
var condition = wpcf7cf_conditions[i];
|
@@ -66,7 +69,7 @@ var cf7signature_resized = 0; // for compatibility with contact-form-7-signature
|
|
66 |
});
|
67 |
|
68 |
if(show == true) {
|
69 |
-
$('#' + unit_tag + ' #' + condition.then_field).
|
70 |
}
|
71 |
|
72 |
continue;
|
@@ -85,7 +88,7 @@ var cf7signature_resized = 0; // for compatibility with contact-form-7-signature
|
|
85 |
condition.operator == 'equals (regex)' && $field.is(':checked') && regex_patt.test($field.val()) ||
|
86 |
condition.operator == 'not equals (regex)' && !$field.is(':checked')
|
87 |
) {
|
88 |
-
$('#'+unit_tag+' #'+condition.then_field).
|
89 |
}
|
90 |
} else if (
|
91 |
( condition.operator == 'equals' && $field.val() == condition.if_value ) ||
|
@@ -99,7 +102,7 @@ var cf7signature_resized = 0; // for compatibility with contact-form-7-signature
|
|
99 |
( condition.operator == 'is empty' && $field.val() == '' ) ||
|
100 |
( condition.operator == 'not empty' && $field.val() != '' )
|
101 |
) {
|
102 |
-
$('#'+unit_tag+' #'+condition.then_field).
|
103 |
}
|
104 |
|
105 |
|
@@ -129,7 +132,7 @@ var cf7signature_resized = 0; // for compatibility with contact-form-7-signature
|
|
129 |
( condition.operator == 'is empty' && checked_values.length == 0 ) ||
|
130 |
( condition.operator == 'not empty' && checked_values.length > 0 )
|
131 |
) {
|
132 |
-
$('#'+unit_tag+' #'+condition.then_field).
|
133 |
}
|
134 |
|
135 |
|
@@ -144,21 +147,59 @@ var cf7signature_resized = 0; // for compatibility with contact-form-7-signature
|
|
144 |
( condition.operator == '>=' && checked_values[ind] >= condition.if_value ) ||
|
145 |
( condition.operator == '<=' && checked_values[ind] <= condition.if_value )
|
146 |
) {
|
147 |
-
$('#'+unit_tag+' #'+condition.then_field).
|
148 |
}
|
149 |
}
|
150 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
|
|
|
|
|
|
|
152 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
153 |
}
|
154 |
|
|
|
|
|
155 |
for (var i = 0; i<options.length; i++) {
|
|
|
156 |
var unit_tag = options[i]['unit_tag'];
|
157 |
var conditions = options[i]['conditions'];
|
158 |
-
|
159 |
-
|
160 |
-
|
|
|
|
|
|
|
|
|
161 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
}
|
163 |
|
164 |
// before the form values are serialized to submit via ajax, we quickly add all invisible fields in the hidden
|
@@ -167,12 +208,8 @@ var cf7signature_resized = 0; // for compatibility with contact-form-7-signature
|
|
167 |
$form = $(form.target);
|
168 |
wpcf7cf_update_hidden_fields($form);
|
169 |
});
|
170 |
-
|
171 |
-
//
|
172 |
-
$('form.wpcf7-form :input').change(function() {
|
173 |
-
wpcf7cf_update_hidden_fields($(this).closest('form'));
|
174 |
-
});
|
175 |
-
// And in case a form gets submitted without any input:
|
176 |
$('form.wpcf7-form').each(function(){
|
177 |
wpcf7cf_update_hidden_fields($(this));
|
178 |
});
|
14 |
}
|
15 |
|
16 |
$(document).ready(function() {
|
17 |
+
function display_fields(unit_tag, wpcf7cf_conditions, wpcf7cf_settings) {
|
18 |
+
|
19 |
+
console.log('display fields');
|
20 |
|
21 |
//for compatibility with contact-form-7-signature-addon
|
22 |
if (cf7signature_resized == 0 && typeof signatures !== 'undefined' && signatures.constructor === Array && signatures.length > 0 ) {
|
31 |
}
|
32 |
}
|
33 |
|
34 |
+
$("#"+unit_tag+" [data-class='wpcf7cf_group']").addClass('wpcf7cf-hidden');
|
35 |
+
|
36 |
for (var i=0; i < wpcf7cf_conditions.length; i++) {
|
37 |
|
38 |
var condition = wpcf7cf_conditions[i];
|
69 |
});
|
70 |
|
71 |
if(show == true) {
|
72 |
+
$('#' + unit_tag + ' #' + condition.then_field).removeClass('wpcf7cf-hidden');
|
73 |
}
|
74 |
|
75 |
continue;
|
88 |
condition.operator == 'equals (regex)' && $field.is(':checked') && regex_patt.test($field.val()) ||
|
89 |
condition.operator == 'not equals (regex)' && !$field.is(':checked')
|
90 |
) {
|
91 |
+
$('#'+unit_tag+' #'+condition.then_field).removeClass('wpcf7cf-hidden');
|
92 |
}
|
93 |
} else if (
|
94 |
( condition.operator == 'equals' && $field.val() == condition.if_value ) ||
|
102 |
( condition.operator == 'is empty' && $field.val() == '' ) ||
|
103 |
( condition.operator == 'not empty' && $field.val() != '' )
|
104 |
) {
|
105 |
+
$('#'+unit_tag+' #'+condition.then_field).removeClass('wpcf7cf-hidden');
|
106 |
}
|
107 |
|
108 |
|
132 |
( condition.operator == 'is empty' && checked_values.length == 0 ) ||
|
133 |
( condition.operator == 'not empty' && checked_values.length > 0 )
|
134 |
) {
|
135 |
+
$('#'+unit_tag+' #'+condition.then_field).removeClass('wpcf7cf-hidden');
|
136 |
}
|
137 |
|
138 |
|
147 |
( condition.operator == '>=' && checked_values[ind] >= condition.if_value ) ||
|
148 |
( condition.operator == '<=' && checked_values[ind] <= condition.if_value )
|
149 |
) {
|
150 |
+
$('#'+unit_tag+' #'+condition.then_field).removeClass('wpcf7cf-hidden');
|
151 |
}
|
152 |
}
|
153 |
}
|
154 |
+
}
|
155 |
+
|
156 |
+
var show_animation = { "height": "show", "marginTop": "show", "marginBottom": "show", "paddingTop": "show", "paddingBottom": "show" };
|
157 |
+
var hide_animation = { "height": "hide", "marginTop": "hide", "marginBottom": "hide", "paddingTop": "hide", "paddingBottom": "hide" };
|
158 |
+
|
159 |
+
var animation_intime = parseInt(wpcf7cf_settings.animation_intime);
|
160 |
+
var animation_outtime = parseInt(wpcf7cf_settings.animation_outtime);
|
161 |
|
162 |
+
if (wpcf7cf_settings.animation == 'no') {
|
163 |
+
animation_intime = 0;
|
164 |
+
animation_outtime = 0;
|
165 |
}
|
166 |
+
|
167 |
+
$("#" + unit_tag + " [data-class='wpcf7cf_group']").each(function (index) {
|
168 |
+
$group = $(this);
|
169 |
+
if ($group.is(':animated')) $group.finish(); // stop any current animations on the group
|
170 |
+
if ($group.css('display') == 'none' && !$group.hasClass('wpcf7cf-hidden')) {
|
171 |
+
$group.animate(show_animation, animation_intime); // show
|
172 |
+
} else if ($group.css('display') != 'none' && $group.hasClass('wpcf7cf-hidden')) {
|
173 |
+
$group.animate(hide_animation, animation_outtime); // hide
|
174 |
+
}
|
175 |
+
});
|
176 |
}
|
177 |
|
178 |
+
var timeout;
|
179 |
+
|
180 |
for (var i = 0; i<options.length; i++) {
|
181 |
+
|
182 |
var unit_tag = options[i]['unit_tag'];
|
183 |
var conditions = options[i]['conditions'];
|
184 |
+
var settings = options[i]['settings'];
|
185 |
+
|
186 |
+
display_fields(unit_tag, conditions, settings);
|
187 |
+
|
188 |
+
$('#'+unit_tag+' input, #'+unit_tag+' select, #'+unit_tag+' textarea').on('input paste change',{unit_tag:unit_tag, conditions:conditions, settings:settings}, function(e) {
|
189 |
+
clearTimeout(timeout);
|
190 |
+
timeout = setTimeout(function() { display_fields(e.data.unit_tag, e.data.conditions, e.data.settings); }, 100);
|
191 |
});
|
192 |
+
|
193 |
+
// $('#'+unit_tag+' input:not([type="radio"]):not([type="checkbox"]), #'+unit_tag+' textarea').on('input paste',{unit_tag:unit_tag, conditions:conditions, settings:settings}, function(e) {
|
194 |
+
// clearTimeout(timeout);
|
195 |
+
// timeout = setTimeout(function() { display_fields(e.data.unit_tag, e.data.conditions, e.data.settings) }, 400);
|
196 |
+
// });
|
197 |
+
|
198 |
+
// bring form in initial state if
|
199 |
+
$('#'+unit_tag+' form').on('reset', {unit_tag:unit_tag, conditions:conditions, settings:settings}, function(e) {
|
200 |
+
setTimeout(function() { display_fields(e.data.unit_tag, e.data.conditions, e.data.settings); }, 200);
|
201 |
+
});
|
202 |
+
|
203 |
}
|
204 |
|
205 |
// before the form values are serialized to submit via ajax, we quickly add all invisible fields in the hidden
|
208 |
$form = $(form.target);
|
209 |
wpcf7cf_update_hidden_fields($form);
|
210 |
});
|
211 |
+
|
212 |
+
// Also add hidden fields in case a form gets submitted without any input:
|
|
|
|
|
|
|
|
|
213 |
$('form.wpcf7-form').each(function(){
|
214 |
wpcf7cf_update_hidden_fields($(this));
|
215 |
});
|
js/scripts_admin.js
CHANGED
@@ -134,5 +134,23 @@ var old_compose = _wpcf7.taggen.compose;
|
|
134 |
update_entries();
|
135 |
});
|
136 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
|
138 |
})( jQuery );
|
134 |
update_entries();
|
135 |
});
|
136 |
|
137 |
+
$(document).ready(function() {
|
138 |
+
|
139 |
+
$('.wpcf7cf-options-notice .notice-dismiss-2').click(function () {
|
140 |
+
$('.wpcf7cf-options-notice .notice-dismiss').click();
|
141 |
+
});
|
142 |
+
$('.wpcf7cf-options-notice .notice-dismiss').click(function () {
|
143 |
+
wpcf7cf_dismiss_notice();
|
144 |
+
});
|
145 |
+
|
146 |
+
function wpcf7cf_dismiss_notice() {
|
147 |
+
$.post(ajaxurl, {action:'wpcf7cf_dismiss_notice'}, function(response) {
|
148 |
+
// nothing to do. dismiss_notice option should be set to TRUE server side by now.
|
149 |
+
});
|
150 |
+
}
|
151 |
+
|
152 |
+
});
|
153 |
+
|
154 |
+
|
155 |
|
156 |
})( jQuery );
|
options.php
ADDED
@@ -0,0 +1,308 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
define('WPCF7CF_SLUG', 'wpcf7cf');
|
4 |
+
define('WPCF7CF_OPTIONS', WPCF7CF_SLUG.'_options');
|
5 |
+
define('WPCF7CF_TEXT_DOMAIN', WPCF7CF_SLUG.'_text_domain');
|
6 |
+
|
7 |
+
define('WPCF7CF_DEFAULT_ANIMATION', 'yes');
|
8 |
+
define('WPCF7CF_DEFAULT_ANIMATION_INTIME', 200);
|
9 |
+
define('WPCF7CF_DEFAULT_ANIMATION_OUTTIME', 200);
|
10 |
+
define('WPCF7CF_DEFAULT_NOTICE_DISMISSED', false);
|
11 |
+
|
12 |
+
$wpcf7cf_default_options = array(
|
13 |
+
'animation' => WPCF7CF_DEFAULT_ANIMATION,
|
14 |
+
'animation_intime' => WPCF7CF_DEFAULT_ANIMATION_INTIME,
|
15 |
+
'animation_outtime' => WPCF7CF_DEFAULT_ANIMATION_OUTTIME,
|
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);
|
22 |
+
if (!is_array($wpcf7cf_options)) $wpcf7cf_options = array();
|
23 |
+
|
24 |
+
if(isset($_POST['reset'])) {
|
25 |
+
update_option(WPCF7CF_OPTIONS, $wpcf7cf_default_options);
|
26 |
+
$wpcf7cf_options['wpcf7cf_settings_saved'] = 0;
|
27 |
+
}
|
28 |
+
|
29 |
+
// this setting will only be 0 as long as the user has not saved any settings. Once the user has saved the WPCF7CF settings, this value will always remain 1.
|
30 |
+
if (!key_exists('wpcf7cf_settings_saved',$wpcf7cf_options)) $wpcf7cf_options['wpcf7cf_settings_saved'] = 0;
|
31 |
+
|
32 |
+
if ($wpcf7cf_options['wpcf7cf_settings_saved'] == 0) {
|
33 |
+
$wpcf7cf_options = $wpcf7cf_default_options;
|
34 |
+
}
|
35 |
+
|
36 |
+
|
37 |
+
add_action('ninja_forms_display_before_field_function','wpcf7cf_wrap_input_field_before');
|
38 |
+
add_action('ninja_forms_display_after_field_function','wpcf7cf_wrap_input_field_after');
|
39 |
+
|
40 |
+
function wpcf7cf_wrap_input_field_before() { echo '<div class="resizable_input_wrapper">'; }
|
41 |
+
function wpcf7cf_wrap_input_field_after() { echo '</div>'; }
|
42 |
+
|
43 |
+
add_action( 'admin_enqueue_scripts', 'wpcf7cf_load_page_options_wp_admin_style' );
|
44 |
+
function wpcf7cf_load_page_options_wp_admin_style() {
|
45 |
+
wp_register_style( 'page_options_wp_admin_css', plugins_url('css/admin-style.css',__FILE__), false, WPCF7CF_VERSION );
|
46 |
+
wp_enqueue_style( 'page_options_wp_admin_css' );
|
47 |
+
}
|
48 |
+
|
49 |
+
|
50 |
+
add_action('admin_menu', 'wpcf7cf_admin_add_page');
|
51 |
+
function wpcf7cf_admin_add_page() {
|
52 |
+
add_submenu_page('wpcf7', 'Conditional Fields', 'Conditional Fields', WPCF7_ADMIN_READ_WRITE_CAPABILITY, 'wpcf7cf', 'wpcf7cf_options_page' );
|
53 |
+
}
|
54 |
+
|
55 |
+
function wpcf7cf_options_page() {
|
56 |
+
global $wpcf7cf_options;
|
57 |
+
|
58 |
+
// Include in admin_enqueue_scripts action hook
|
59 |
+
wp_enqueue_media();
|
60 |
+
//wp_enqueue_script( 'custom-background' );
|
61 |
+
wp_enqueue_script( 'wpcf7cf-image-upload', plugins_url('framework/js/bdwm-image-upload.js',__FILE__), array('jquery'), '1.0.0', true );
|
62 |
+
|
63 |
+
if (isset($_POST['reset'])) {
|
64 |
+
echo '<div id="message" class="updated fade"><p><strong>Settings restored to defaults</strong></p></div>';
|
65 |
+
} else if ($_REQUEST['settings-updated']) {
|
66 |
+
echo '<div id="message" class="updated fade"><p><strong>Settings updated</strong></p></div>';
|
67 |
+
}
|
68 |
+
|
69 |
+
?>
|
70 |
+
|
71 |
+
<div class="wrap wpcf7cf-admin-wrap">
|
72 |
+
<?php screen_icon(); ?>
|
73 |
+
<h2>Conditional Fields for Contact Form 7 Settings</h2>
|
74 |
+
<?php if (!$wpcf7cf_options['notice_dismissed']) { ?>
|
75 |
+
<div class="wpcf7cf-options-notice notice notice-warning is-dismissible"><div style="padding: 10px 0;"><strong>Notice</strong>: These are global settings for Conditional Fields for Contact Form 7. <br><br><strong>How to create/edit conditional fields?</strong>
|
76 |
+
<ol>
|
77 |
+
<li>Create a new Contact Form or edit an existing one</li>
|
78 |
+
<li>Create at least one [group] inside the form</li>
|
79 |
+
<li>Save the Contact Form</li>
|
80 |
+
<li>go to the <strong><em>Conditional Fields</em></strong> Tab</li>
|
81 |
+
</ol>
|
82 |
+
<a href="#">Show me an example</a> | <a class="notice-dismiss-2" href="#">Dismiss notice</a>
|
83 |
+
</div></div>
|
84 |
+
<?php } ?>
|
85 |
+
<form action="options.php" method="post">
|
86 |
+
<?php settings_fields(WPCF7CF_OPTIONS); ?>
|
87 |
+
|
88 |
+
<input type="hidden" value="1" id="wpcf7cf_settings_saved" name="<?php echo WPCF7CF_OPTIONS.'[wpcf7cf_settings_saved]' ?>">
|
89 |
+
|
90 |
+
<h3>Default animation Settings</h3>
|
91 |
+
|
92 |
+
<?php
|
93 |
+
|
94 |
+
wpcf7cf_input_select('animation', array(
|
95 |
+
'label' => 'Animation',
|
96 |
+
'description' => 'Use animations while showing/hiding groups',
|
97 |
+
'options' => array('no'=> 'Disabled', 'yes' => 'Enabled')
|
98 |
+
));
|
99 |
+
|
100 |
+
wpcf7cf_input_field('animation_intime', array(
|
101 |
+
'label' => 'Animation In time',
|
102 |
+
'description' => 'A positive integer value indicating the time, in milliseconds, it will take for each group to show.',
|
103 |
+
));
|
104 |
+
|
105 |
+
wpcf7cf_input_field('animation_outtime', array(
|
106 |
+
'label' => 'Animation Out Time',
|
107 |
+
'description' => 'A positive integer value indicating the time, in milliseconds, it will take for each group to hide.',
|
108 |
+
));
|
109 |
+
|
110 |
+
submit_button();
|
111 |
+
|
112 |
+
do_action('wpcf7cf_after_animation_settings');
|
113 |
+
|
114 |
+
?>
|
115 |
+
|
116 |
+
</form></div>
|
117 |
+
|
118 |
+
<h3>Restore Default Settings</h3>
|
119 |
+
<form method="post" id="reset-form" action="">
|
120 |
+
<p class="submit">
|
121 |
+
<input name="reset" class="button button-secondary" type="submit" value="Restore defaults" >
|
122 |
+
<input type="hidden" name="action" value="reset" />
|
123 |
+
</p>
|
124 |
+
</form>
|
125 |
+
<script>
|
126 |
+
(function($){
|
127 |
+
$('#reset-form').submit(function() {
|
128 |
+
return confirm('Are you sure you want to reset the plugin settings to the default values? All changes you have previously made will be lost.');
|
129 |
+
});
|
130 |
+
}(jQuery))
|
131 |
+
</script>
|
132 |
+
|
133 |
+
<?php
|
134 |
+
}
|
135 |
+
|
136 |
+
|
137 |
+
function wpcf7cf_image_field($slug, $args) {
|
138 |
+
|
139 |
+
global $wpcf7cf_options, $wpcf7cf_default_options;
|
140 |
+
|
141 |
+
$defaults = array(
|
142 |
+
'title'=>'Image',
|
143 |
+
'description' => '',
|
144 |
+
'choose_text' => 'Choose an image',
|
145 |
+
'update_text' => 'Use image',
|
146 |
+
'default' => $wpcf7cf_default_options[$slug]
|
147 |
+
);
|
148 |
+
|
149 |
+
$args = wp_parse_args( $args, $defaults );
|
150 |
+
extract($args);
|
151 |
+
$label; $description; $choose_text; $update_text; $default;
|
152 |
+
|
153 |
+
if (!key_exists($slug, $wpcf7cf_options)) {
|
154 |
+
$wpcf7cf_options[$slug] = $default;
|
155 |
+
}
|
156 |
+
|
157 |
+
?>
|
158 |
+
<div class="option-line">
|
159 |
+
<span class="label"><?php echo $label; ?></span>
|
160 |
+
<?php
|
161 |
+
if ($description) {
|
162 |
+
?>
|
163 |
+
<p><?php echo $description; ?></p>
|
164 |
+
<?php
|
165 |
+
}
|
166 |
+
?>
|
167 |
+
<div>
|
168 |
+
<div class="image-container" id="default-thumbnail-preview_<?php echo $slug ?>">
|
169 |
+
<?php
|
170 |
+
if ($wpcf7cf_options[$slug] != '') {
|
171 |
+
$img_info = wp_get_attachment_image_src($wpcf7cf_options[$slug], 'full');
|
172 |
+
$img_src = $img_info[0];
|
173 |
+
?>
|
174 |
+
<img src="<?php echo $img_src ?>" height="100">
|
175 |
+
<?php
|
176 |
+
}
|
177 |
+
?>
|
178 |
+
</div>
|
179 |
+
<a class="choose-from-library-link" href="#"
|
180 |
+
data-field="<?php echo WPCF7CF_OPTIONS.'_'.$slug ?>"
|
181 |
+
data-image_container="default-thumbnail-preview_<?php echo $slug ?>"
|
182 |
+
data-choose="<?php echo $choose_text; ?>"
|
183 |
+
data-update="<?php echo $update_text; ?>"><?php _e( 'Choose image' ); ?>
|
184 |
+
</a>
|
185 |
+
<input type="hidden" value="<?php echo $wpcf7cf_options[$slug] ?>" id="<?php echo WPCF7CF_OPTIONS.'_'.$slug ?>" name="<?php echo WPCF7CF_OPTIONS.'['.$slug.']' ?>">
|
186 |
+
</div>
|
187 |
+
</div>
|
188 |
+
<?php
|
189 |
+
|
190 |
+
}
|
191 |
+
|
192 |
+
function wpcf7cf_input_field($slug, $args) {
|
193 |
+
global $wpcf7cf_options, $wpcf7cf_default_options;
|
194 |
+
|
195 |
+
$defaults = array(
|
196 |
+
'label'=>'',
|
197 |
+
'desription' => '',
|
198 |
+
'default' => $wpcf7cf_default_options[$slug]
|
199 |
+
);
|
200 |
+
|
201 |
+
$args = wp_parse_args( $args, $defaults );
|
202 |
+
extract($args);
|
203 |
+
|
204 |
+
$label; $description; $default;
|
205 |
+
|
206 |
+
if (!key_exists($slug, $wpcf7cf_options)) {
|
207 |
+
$wpcf7cf_options[$slug] = $default;
|
208 |
+
}
|
209 |
+
|
210 |
+
?>
|
211 |
+
<div class="option-line">
|
212 |
+
<span class="label"><?php echo $label ?></span>
|
213 |
+
<span class="field"><input type="text" data-default-value="<?php echo $default ?>" value="<?php echo $wpcf7cf_options[$slug] ?>" id="<?php echo WPCF7CF_OPTIONS.'_'.$slug ?>" name="<?php echo WPCF7CF_OPTIONS.'['.$slug.']' ?>"></span>
|
214 |
+
<span class="description"><?php echo $description ?><?php if (!empty($default)) echo ' (Default: '.$default.')' ?></span>
|
215 |
+
</div>
|
216 |
+
<?php
|
217 |
+
|
218 |
+
}
|
219 |
+
|
220 |
+
function wpcf7cf_input_select($slug, $args) {
|
221 |
+
global $wpcf7cf_options, $wpcf7cf_default_options;
|
222 |
+
|
223 |
+
$defaults = array(
|
224 |
+
'label'=>'',
|
225 |
+
'desription' => '',
|
226 |
+
'options' => array(), // array($name => $value)
|
227 |
+
'default' => $wpcf7cf_default_options[$slug],
|
228 |
+
);
|
229 |
+
|
230 |
+
$args = wp_parse_args( $args, $defaults );
|
231 |
+
extract($args);
|
232 |
+
|
233 |
+
$label; $description; $options; $default;
|
234 |
+
|
235 |
+
if (!key_exists($slug, $wpcf7cf_options)) {
|
236 |
+
$wpcf7cf_options[$slug] = $default;
|
237 |
+
}
|
238 |
+
|
239 |
+
// $first_element = array('-1' => '-- Select --');
|
240 |
+
// $options = array_merge($first_element, $options);
|
241 |
+
|
242 |
+
?>
|
243 |
+
<div class="option-line">
|
244 |
+
<span class="label"><?php echo $label ?></span>
|
245 |
+
<span class="field">
|
246 |
+
<select id="<?php echo WPCF7CF_OPTIONS.'_'.$slug ?>" data-default-value="<?php echo $default ?>" name="<?php echo WPCF7CF_OPTIONS.'['.$slug.']' ?>">
|
247 |
+
<?php
|
248 |
+
foreach($options as $value => $text) {
|
249 |
+
?>
|
250 |
+
<option value="<?php echo $value ?>" <?php echo $wpcf7cf_options[$slug]==$value?'selected':'' ?>><?php echo $text ?></option>
|
251 |
+
<?php
|
252 |
+
}
|
253 |
+
?>
|
254 |
+
</select>
|
255 |
+
</span>
|
256 |
+
<span class="description"><?php echo $description ?><?php if (!empty($default)) echo ' (Default: '.$options[$default].')' ?></span>
|
257 |
+
</div>
|
258 |
+
<?php
|
259 |
+
|
260 |
+
}
|
261 |
+
|
262 |
+
function wpcf7cf_checkbox($slug, $args) {
|
263 |
+
global $wpcf7cf_options, $wpcf7cf_default_options;
|
264 |
+
|
265 |
+
$defaults = array(
|
266 |
+
'label'=>'',
|
267 |
+
'desription' => '',
|
268 |
+
'default' => $wpcf7cf_default_options[$slug],
|
269 |
+
);
|
270 |
+
|
271 |
+
$args = wp_parse_args( $args, $defaults );
|
272 |
+
extract($args);
|
273 |
+
|
274 |
+
$label; $description; $default;
|
275 |
+
|
276 |
+
?>
|
277 |
+
<div class="option-line">
|
278 |
+
<span class="label"><?php echo $label ?></span>
|
279 |
+
<span class="field">
|
280 |
+
|
281 |
+
<input type="checkbox" data-default-value="<?php echo $default ?>" name="<?php echo WPCF7CF_OPTIONS.'['.$slug.']' ?>" value="1" <?php checked('1', $wpcf7cf_options[$slug]) ?>>
|
282 |
+
</span>
|
283 |
+
<span class="description"><?php echo $description ?><?php if (!empty($default)) echo ' (Default: '.$default.')' ?></span>
|
284 |
+
</div>
|
285 |
+
<?php
|
286 |
+
}
|
287 |
+
|
288 |
+
function wpcf7cf_regex_collection() {
|
289 |
+
global $wpcf7cf_options, $wpcf7cf_default_options;
|
290 |
+
|
291 |
+
}
|
292 |
+
|
293 |
+
add_action('admin_init', 'wpcf7cf_admin_init');
|
294 |
+
function wpcf7cf_admin_init(){
|
295 |
+
register_setting( WPCF7CF_OPTIONS, WPCF7CF_OPTIONS, 'wpcf7cf_options_sanitize' );
|
296 |
+
}
|
297 |
+
|
298 |
+
function wpcf7cf_options_sanitize($input) {
|
299 |
+
return $input;
|
300 |
+
}
|
301 |
+
|
302 |
+
add_action( 'wp_ajax_wpcf7cf_dismiss_notice', 'wpcf7cf_dismiss_notice' );
|
303 |
+
function wpcf7cf_dismiss_notice() {
|
304 |
+
global $wpcf7cf_options;
|
305 |
+
$wpcf7cf_options['notice_dismissed'] = true;
|
306 |
+
$wpcf7cf_options['wpcf7cf_settings_saved'] = 1;
|
307 |
+
update_option(WPCF7CF_OPTIONS,$wpcf7cf_options);
|
308 |
+
}
|
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.2
|
9 |
-
Stable tag: 1.
|
10 |
License: GPLv2 or later
|
11 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
12 |
|
@@ -83,6 +83,13 @@ I will assume that you successfully installed both plugins, that you were able t
|
|
83 |
|
84 |
== Changelog ==
|
85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
= 1.2.3 =
|
87 |
* Make plugin compatible with CF7 Multi Step by NinjaTeam https://wordpress.org/plugins/cf7-multi-step/
|
88 |
* Improve compatibility with Signature Addon some more.
|
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.3
|
10 |
License: GPLv2 or later
|
11 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
12 |
|
83 |
|
84 |
== Changelog ==
|
85 |
|
86 |
+
= 1.3 =
|
87 |
+
* Fixed small bug with integration with Contact Form 7 Multi-Step Forms
|
88 |
+
* Also trigger hiding/showing of groups while typing or pasting text in input fields
|
89 |
+
* Added support for input type="reset"
|
90 |
+
* Added animations
|
91 |
+
* Added settings page to wp-admin: Contact > Conditional Fields
|
92 |
+
|
93 |
= 1.2.3 =
|
94 |
* Make plugin compatible with CF7 Multi Step by NinjaTeam https://wordpress.org/plugins/cf7-multi-step/
|
95 |
* Improve compatibility with Signature Addon some more.
|
style.css
CHANGED
@@ -1 +1,4 @@
|
|
1 |
-
|
|
|
|
|
|
1 |
+
/* initially hide all groups (even before JS is loaded), so the page will never render them while loading */
|
2 |
+
[data-class="wpcf7cf_group"] {
|
3 |
+
display:none;
|
4 |
+
}
|