Version Description
- (08-15-18) Added basic drag and drop functionality to the back-end so conditional rules can be rearranged.
- (08-12-18) Added possibility to create inline groups by adding the option inline. Example:
[group my-group inline] ... [/group]
- (08-12-18) Added property clear_on_hide to clear all fields within a group the moment the group gets hidden. Example:
[group my-group clear_on_hide] ... [/group]
- (08-12-18) Added AND conditions and added a bunch of other options in the PRO version (should be released very soon now)
- (08-12-18) Bug fix thanks to Aurovrata Venet (@aurovrata) https://wordpress.org/support/topic/bug-plugin-overwrite-cf7-hidden-fields/
- (06-28-18) Bug fix thanks to 972 creative (@toddedelman) https://wordpress.org/support/topic/conditional-fields-not-opening-using-radio-buttons/#post-10442923
Download this release
Release Info
Developer | Jules Colle |
Plugin | Conditional Fields for Contact Form 7 |
Version | 1.4 |
Comparing to | |
See all releases |
Code changes from version 1.3.4 to 1.4
- admin-style.css +180 -4
- admin.php +103 -51
- cf7cf.php +32 -15
- contact-form-7-conditional-fields.php +2 -30
- init.php +33 -0
- js/scripts.js +161 -104
- js/scripts_admin.js +201 -92
- readme.txt +17 -56
- screenshot-1.png +0 -0
- screenshot-2.png +0 -0
- style.css +1 -1
- tg_pane_group.php +10 -0
- wpcf7cf-options.php +6 -10
admin-style.css
CHANGED
@@ -1,8 +1,6 @@
|
|
1 |
-
#wpcf7cf-add-button, .delete-button { text-decoration: none; display: inline-block; vertical-align: baseline; color:#4ed521; }
|
2 |
-
.delete-button { color: #d54e21 !important; }
|
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;
|
@@ -35,4 +33,182 @@
|
|
35 |
|
36 |
.ui-autocomplete-term {
|
37 |
font-weight: bold;
|
38 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
#wpcf7cf-new-entry { display: inline-block; display:none; }
|
2 |
#wpcf7cf-delete-button { display: none; }
|
3 |
+
#wpcf7cf-settings-text { width: 100%; height: 280px; font-family: "Courier New", Courier, monospace; }
|
4 |
|
5 |
.wpcf7cf-admin-wrap .label, .wpcf7cf-admin-wrap .field, .wpcf7cf-admin-wrap .description {
|
6 |
padding: 10px;
|
33 |
|
34 |
.ui-autocomplete-term {
|
35 |
font-weight: bold;
|
36 |
+
}
|
37 |
+
|
38 |
+
.wpcf7cf-admin-wrap .option-line > .label.editable {
|
39 |
+
position: relative;
|
40 |
+
}
|
41 |
+
|
42 |
+
.wpcf7cf-admin-wrap .option-line > .label.editable input {
|
43 |
+
background-color: transparent;
|
44 |
+
border-width: 0;
|
45 |
+
outline: none;
|
46 |
+
box-shadow: none;
|
47 |
+
padding: 0;
|
48 |
+
}
|
49 |
+
|
50 |
+
.wpcf7cf-admin-wrap .option-line > .label.editable input:after {
|
51 |
+
content: "edit";
|
52 |
+
display: block;
|
53 |
+
width: 10px;
|
54 |
+
right:0;
|
55 |
+
position: absolute;
|
56 |
+
}
|
57 |
+
|
58 |
+
.wpcf7cf-admin-wrap .option-line > .label.editable input:focus {
|
59 |
+
background: #fff;
|
60 |
+
box-shadow: inset 0 1px 2px rgba(0,0,0,.07) ;
|
61 |
+
border: 1px solid #ddd;
|
62 |
+
padding: 2px;
|
63 |
+
}
|
64 |
+
|
65 |
+
.wpcf7cf-admin-wrap .option-line > .label.editable input:focus:after {
|
66 |
+
content: "";
|
67 |
+
}
|
68 |
+
|
69 |
+
.wpcf7cf-and {
|
70 |
+
display: inline-block;
|
71 |
+
}
|
72 |
+
|
73 |
+
.wpcf7cf-and-rules, .wpcf7cf-if {
|
74 |
+
display: inline-block;
|
75 |
+
vertical-align: top;
|
76 |
+
}
|
77 |
+
|
78 |
+
#wpcf7cf-entries input, #wpcf7cf-entries select, .and-button, .delete-button, #wpcf7cf-entries .if-txt, #wpcf7cf-entries .label, #wpcf7cf-add-button {
|
79 |
+
position:relative;
|
80 |
+
display: inline-block;
|
81 |
+
vertical-align: bottom;
|
82 |
+
margin:2px;
|
83 |
+
padding: 3px;
|
84 |
+
background: #fefefe;
|
85 |
+
border: 1px solid #bababa;
|
86 |
+
box-shadow: none;
|
87 |
+
height: 22px;
|
88 |
+
line-height: 22px;
|
89 |
+
box-sizing: content-box;
|
90 |
+
}
|
91 |
+
|
92 |
+
#wpcf7cf-entries .label {
|
93 |
+
background-color: transparent;
|
94 |
+
border: none;
|
95 |
+
}
|
96 |
+
|
97 |
+
.and-button, .delete-button, #wpcf7cf-add-button {
|
98 |
+
border: 1px solid #4ed521;
|
99 |
+
color: #007b04;
|
100 |
+
cursor: pointer;
|
101 |
+
font-size: 11px;
|
102 |
+
font-weight: bold;
|
103 |
+
-webkit-touch-callout: none; /* iOS Safari */
|
104 |
+
-webkit-user-select: none; /* Safari */
|
105 |
+
-khtml-user-select: none; /* Konqueror HTML */
|
106 |
+
-moz-user-select: none; /* Firefox */
|
107 |
+
-ms-user-select: none; /* Internet Explorer/Edge */
|
108 |
+
user-select: none; /* Non-prefixed version, currently */
|
109 |
+
background-color: rgba(75, 169, 61, 0.11);
|
110 |
+
}
|
111 |
+
|
112 |
+
#wpcf7cf-add-button {
|
113 |
+
margin-top: 10px;
|
114 |
+
text-align: center;
|
115 |
+
padding-left: 20px;
|
116 |
+
padding-right:20px;
|
117 |
+
}
|
118 |
+
|
119 |
+
.and-button:hover {
|
120 |
+
background-color: rgba(75, 169, 61, 0.2);
|
121 |
+
}
|
122 |
+
|
123 |
+
.delete-button {
|
124 |
+
border: 1px solid #bababa;
|
125 |
+
color: #858585;
|
126 |
+
background-color: transparent;
|
127 |
+
margin-left: 42px;
|
128 |
+
}
|
129 |
+
|
130 |
+
.delete-button:hover {
|
131 |
+
background-color: rgba(133, 133, 133, 0.11);
|
132 |
+
|
133 |
+
}
|
134 |
+
|
135 |
+
.and-button {
|
136 |
+
display:none;
|
137 |
+
width: 30px;
|
138 |
+
text-align: center;
|
139 |
+
}
|
140 |
+
.wpcf7cf-and-rule:first-child .and-button {
|
141 |
+
display: inline-block;
|
142 |
+
vertical-align: top;
|
143 |
+
height: 22px;
|
144 |
+
position: absolute;
|
145 |
+
line-height: 22px;
|
146 |
+
right: 50px;
|
147 |
+
top: 0;
|
148 |
+
}
|
149 |
+
|
150 |
+
.wpcf7cf-and-rule {
|
151 |
+
margin-bottom: 4px;
|
152 |
+
height: 30px;
|
153 |
+
}
|
154 |
+
|
155 |
+
.wpcf7cf-and-rule .if-txt, .wpcf7cf-if > .label {
|
156 |
+
cursor: n-resize;
|
157 |
+
}
|
158 |
+
|
159 |
+
|
160 |
+
|
161 |
+
.wpcf7cf-and-rule .if-txt:before {
|
162 |
+
content: 'and';
|
163 |
+
position: absolute;
|
164 |
+
width: 30px;
|
165 |
+
text-align: right;
|
166 |
+
left: -34px;
|
167 |
+
}
|
168 |
+
|
169 |
+
.wpcf7cf-and-rule:first-child .if-txt:before {
|
170 |
+
display:none;
|
171 |
+
}
|
172 |
+
|
173 |
+
#contitional-panel {
|
174 |
+
overflow-x: auto;
|
175 |
+
}
|
176 |
+
|
177 |
+
.wpcf7cf-inner-container {
|
178 |
+
min-width: 800px;
|
179 |
+
}
|
180 |
+
|
181 |
+
.entry {
|
182 |
+
box-sizing: border-box;
|
183 |
+
display:flex;
|
184 |
+
}
|
185 |
+
|
186 |
+
.entry .wpcf7cf-if {
|
187 |
+
width: 188px;
|
188 |
+
}
|
189 |
+
.then-field-select {
|
190 |
+
width: 130px;
|
191 |
+
}
|
192 |
+
|
193 |
+
|
194 |
+
.entry .wpcf7cf-and-rules {
|
195 |
+
flex:1;
|
196 |
+
position:relative;
|
197 |
+
|
198 |
+
}
|
199 |
+
.wpcf7cf-and-rule {
|
200 |
+
display:flex;
|
201 |
+
}
|
202 |
+
.if-txt {
|
203 |
+
width: 14px;
|
204 |
+
text-align: center;
|
205 |
+
}
|
206 |
+
|
207 |
+
.operator {
|
208 |
+
/*width:140px;*/
|
209 |
+
}
|
210 |
+
|
211 |
+
.if-value {
|
212 |
+
flex:1;
|
213 |
+
margin-right:3px !important;
|
214 |
+
}
|
admin.php
CHANGED
@@ -7,7 +7,7 @@ function wpcf7cf_admin_enqueue_scripts( $hook_suffix ) {
|
|
7 |
return; //don't load styles and scripts if this isn't a CF7 page.
|
8 |
}
|
9 |
|
10 |
-
wp_enqueue_script('cf7cf-scripts-admin', wpcf7cf_plugin_url( 'js/scripts_admin.js' ),array('jquery-ui-autocomplete'), WPCF7CF_VERSION,true);
|
11 |
wp_localize_script('cf7cf-scripts-admin', 'wpcf7cf_options_0', get_option(WPCF7CF_OPTIONS));
|
12 |
|
13 |
}
|
@@ -67,57 +67,40 @@ function wpcf7cf_editor_panel_conditional($form) {
|
|
67 |
|
68 |
if (!is_array($wpcf7cf_entries)) $wpcf7cf_entries = array();
|
69 |
|
|
|
70 |
|
71 |
?>
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
?>
|
104 |
-
</div>
|
105 |
-
|
106 |
-
|
107 |
-
<div id="wpcf7cf-text-entries">
|
108 |
-
<p><a href="#" id="wpcf7cf-settings-to-text">import/export</a></p>
|
109 |
-
<div id="wpcf7cf-settings-text-wrap">
|
110 |
-
<textarea id="wpcf7cf-settings-text"></textarea>
|
111 |
-
<br>
|
112 |
-
Import actions (Beta feature!):
|
113 |
-
<input type="button" value="Add conditions" id="add-fields" >
|
114 |
-
<input type="button" value="Overwrite conditions" id="overwrite-fields" >
|
115 |
-
<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>
|
116 |
-
|
117 |
-
<p><a href="#" id="wpcf7cf-settings-text-clear">Clear</a></p>
|
118 |
-
|
119 |
-
</div>
|
120 |
-
</div>
|
121 |
<?php
|
122 |
}
|
123 |
|
@@ -141,4 +124,73 @@ function wpcf7cf_save_contact_form( $contact_form )
|
|
141 |
};
|
142 |
|
143 |
// add the action
|
144 |
-
add_action( 'wpcf7_save_contact_form', 'wpcf7cf_save_contact_form', 10, 1 );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
return; //don't load styles and scripts if this isn't a CF7 page.
|
8 |
}
|
9 |
|
10 |
+
wp_enqueue_script('cf7cf-scripts-admin', wpcf7cf_plugin_url( 'js/scripts_admin.js' ),array('jquery-ui-autocomplete', 'jquery-ui-sortable'), WPCF7CF_VERSION,true);
|
11 |
wp_localize_script('cf7cf-scripts-admin', 'wpcf7cf_options_0', get_option(WPCF7CF_OPTIONS));
|
12 |
|
13 |
}
|
67 |
|
68 |
if (!is_array($wpcf7cf_entries)) $wpcf7cf_entries = array();
|
69 |
|
70 |
+
$wpcf7cf_entries = array_values($wpcf7cf_entries);
|
71 |
|
72 |
?>
|
73 |
+
<div class="wpcf7cf-inner-container">
|
74 |
+
<h3><?php echo esc_html( __( 'Conditional fields', 'wpcf7cf' ) ); ?></h3>
|
75 |
+
|
76 |
+
<?php
|
77 |
+
print_entries_html($form);
|
78 |
+
?>
|
79 |
+
|
80 |
+
<div id="wpcf7cf-entries">
|
81 |
+
<!-- <pre>--><?php //print_r($wpcf7cf_entries) ?><!--</pre>-->
|
82 |
+
<?php
|
83 |
+
print_entries_html($form, $wpcf7cf_entries);
|
84 |
+
?>
|
85 |
+
</div>
|
86 |
+
|
87 |
+
<span id="wpcf7cf-add-button" title="add new rule">+ add new conditional rule</span>
|
88 |
+
|
89 |
+
<div id="wpcf7cf-text-entries">
|
90 |
+
<p><a href="#" id="wpcf7cf-settings-to-text">import/export</a></p>
|
91 |
+
<div id="wpcf7cf-settings-text-wrap">
|
92 |
+
<textarea id="wpcf7cf-settings-text"></textarea>
|
93 |
+
<br>
|
94 |
+
Import actions (Beta feature!):
|
95 |
+
<input type="button" value="Add conditions" id="add-fields" >
|
96 |
+
<input type="button" value="Overwrite conditions" id="overwrite-fields" >
|
97 |
+
<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>
|
98 |
+
|
99 |
+
<p><a href="#" id="wpcf7cf-settings-text-clear">Clear</a></p>
|
100 |
+
|
101 |
+
</div>
|
102 |
+
</div>
|
103 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
<?php
|
105 |
}
|
106 |
|
124 |
};
|
125 |
|
126 |
// add the action
|
127 |
+
add_action( 'wpcf7_save_contact_form', 'wpcf7cf_save_contact_form', 10, 1 );
|
128 |
+
|
129 |
+
function print_entries_html($form, $wpcf7cf_entries = false) {
|
130 |
+
|
131 |
+
$is_dummy = !$wpcf7cf_entries;
|
132 |
+
|
133 |
+
if ($is_dummy) {
|
134 |
+
$wpcf7cf_entries = array(
|
135 |
+
'{id}' => array(
|
136 |
+
'then_field' => '-1',
|
137 |
+
'and_rules' => array(
|
138 |
+
0 => array(
|
139 |
+
'if_field' => '-1',
|
140 |
+
'operator' => 'equals',
|
141 |
+
'if_value' => ''
|
142 |
+
)
|
143 |
+
)
|
144 |
+
)
|
145 |
+
);
|
146 |
+
}
|
147 |
+
|
148 |
+
foreach($wpcf7cf_entries as $i => $entry) {
|
149 |
+
|
150 |
+
// check for backwards compatibility ( < 2.0 )
|
151 |
+
if (!key_exists('and_rules', $wpcf7cf_entries[$i]) || !is_array($wpcf7cf_entries[$i]['and_rules'])) {
|
152 |
+
$wpcf7cf_entries[$i]['and_rules'][0] = $wpcf7cf_entries[$i];
|
153 |
+
}
|
154 |
+
|
155 |
+
$and_entries = array_values($wpcf7cf_entries[$i]['and_rules']);
|
156 |
+
|
157 |
+
if ($is_dummy) {
|
158 |
+
?>
|
159 |
+
<div id="wpcf7cf-new-entry">
|
160 |
+
<?php
|
161 |
+
} else {
|
162 |
+
?>
|
163 |
+
<div class="entry" id="entry-<?php echo $i ?>">
|
164 |
+
<?php
|
165 |
+
}
|
166 |
+
?>
|
167 |
+
<div class="wpcf7cf-if">
|
168 |
+
<span class="label">Show</span>
|
169 |
+
<select name="wpcf7cf_options[<?php echo $i ?>][then_field]" class="then-field-select"><?php wpcf7cf_all_group_options($form, $entry['then_field']); ?></select>
|
170 |
+
</div>
|
171 |
+
<div class="wpcf7cf-and-rules" data-next-index="<?php echo count($and_entries) ?>">
|
172 |
+
<?php
|
173 |
+
|
174 |
+
|
175 |
+
|
176 |
+
foreach($and_entries as $and_i => $and_entry) {
|
177 |
+
?>
|
178 |
+
<div class="wpcf7cf-and-rule">
|
179 |
+
<span class="rule-part if-txt label">if</span>
|
180 |
+
<select name="wpcf7cf_options[<?php echo $i ?>][and_rules][<?php echo $and_i ?>][if_field]"
|
181 |
+
class="rule-part if-field-select"><?php wpcf7cf_all_field_options( $form, $and_entry['if_field'] ); ?></select>
|
182 |
+
<select name="wpcf7cf_options[<?php echo $i ?>][and_rules][<?php echo $and_i ?>][operator]"
|
183 |
+
class="rule-part operator"><?php all_operator_options( $and_entry['operator'] ) ?></select>
|
184 |
+
<input name="wpcf7cf_options[<?php echo $i ?>][and_rules][<?php echo $and_i ?>][if_value]" class="rule-part if-value" type="text"
|
185 |
+
placeholder="value" value="<?php echo $and_entry['if_value'] ?>">
|
186 |
+
<span class="and-button">And</span>
|
187 |
+
<span title="delete rule" class="rule-part delete-button">remove</span>
|
188 |
+
</div>
|
189 |
+
<?php
|
190 |
+
}
|
191 |
+
?>
|
192 |
+
</div>
|
193 |
+
</div>
|
194 |
+
<?php
|
195 |
+
}
|
196 |
+
}
|
cf7cf.php
CHANGED
@@ -260,22 +260,39 @@ function wpcf7cf_properties($properties, $wpcf7form) {
|
|
260 |
if (!is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) { // TODO: kind of hacky. maybe find a better solution. Needed because otherwise the group tags will be replaced in the editor as well.
|
261 |
$form = $properties['form'];
|
262 |
|
263 |
-
|
264 |
-
'/\[group\s*\]/s', // matches [group ] or [group]
|
265 |
-
'/\[group\s+([^\s\]]*)\s*([^\]]*)\]/s', // matches [group something some:thing] or [group something som ]
|
266 |
-
// doesn't match [group-special something]
|
267 |
-
'/\[\/group\]/s'
|
268 |
-
);
|
269 |
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
|
|
|
|
|
|
|
|
275 |
|
276 |
-
|
|
|
|
|
277 |
|
278 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
279 |
}
|
280 |
return $properties;
|
281 |
}
|
@@ -299,12 +316,12 @@ function wpcf7cf_form_hidden_fields($hidden_fields) {
|
|
299 |
'settings' => get_option(WPCF7CF_OPTIONS)
|
300 |
);
|
301 |
|
302 |
-
|
303 |
'_wpcf7cf_hidden_group_fields' => '',
|
304 |
'_wpcf7cf_hidden_groups' => '',
|
305 |
'_wpcf7cf_visible_groups' => '',
|
306 |
'_wpcf7cf_options' => ''.json_encode($options),
|
307 |
-
);
|
308 |
}
|
309 |
|
310 |
function wpcf7cf_endswith($string, $test) {
|
260 |
if (!is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) { // TODO: kind of hacky. maybe find a better solution. Needed because otherwise the group tags will be replaced in the editor as well.
|
261 |
$form = $properties['form'];
|
262 |
|
263 |
+
$form_parts = preg_split('/(\[\/?group(?:\]|\s.*?\]))/',$form, -1,PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
|
|
|
|
|
|
|
|
|
|
|
264 |
|
265 |
+
ob_start();
|
266 |
+
|
267 |
+
$stack = array();
|
268 |
+
|
269 |
+
foreach ($form_parts as $form_part) {
|
270 |
+
if (substr($form_part,0,7) == '[group ') {
|
271 |
+
$tag_parts = explode(' ',rtrim($form_part,']'));
|
272 |
+
|
273 |
+
array_shift($tag_parts);
|
274 |
|
275 |
+
$tag_id = $tag_parts[0];
|
276 |
+
$tag_html_type = 'div';
|
277 |
+
$tag_html_data = array();
|
278 |
|
279 |
+
foreach ($tag_parts as $i => $tag_part) {
|
280 |
+
if ($i==0) continue;
|
281 |
+
else if ($tag_part == 'inline') $tag_html_type = 'span';
|
282 |
+
else if ($tag_part == 'clear_on_hide') $tag_html_data[] = 'data-clear_on_hide';
|
283 |
+
}
|
284 |
+
|
285 |
+
array_push($stack,$tag_html_type);
|
286 |
+
|
287 |
+
echo '<'.$tag_html_type.' id="'.$tag_id.'" '.implode(' ',$tag_html_data).' data-class="wpcf7cf_group">';
|
288 |
+
} else if ($form_part == '[/group]') {
|
289 |
+
echo '</'.array_pop($stack).'>';
|
290 |
+
} else {
|
291 |
+
echo $form_part;
|
292 |
+
}
|
293 |
+
}
|
294 |
+
|
295 |
+
$properties['form'] = ob_get_clean();
|
296 |
}
|
297 |
return $properties;
|
298 |
}
|
316 |
'settings' => get_option(WPCF7CF_OPTIONS)
|
317 |
);
|
318 |
|
319 |
+
return array_merge($hidden_fields, array(
|
320 |
'_wpcf7cf_hidden_group_fields' => '',
|
321 |
'_wpcf7cf_hidden_groups' => '',
|
322 |
'_wpcf7cf_visible_groups' => '',
|
323 |
'_wpcf7cf_options' => ''.json_encode($options),
|
324 |
+
));
|
325 |
}
|
326 |
|
327 |
function wpcf7cf_endswith($string, $test) {
|
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,32 +24,4 @@ Author URI: http://bdwm.be/
|
|
24 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
25 |
*/
|
26 |
|
27 |
-
|
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 ) );
|
31 |
-
if (!defined('WPCF7CF_PLUGIN_NAME')) define( 'WPCF7CF_PLUGIN_NAME', trim( dirname( WPCF7CF_PLUGIN_BASENAME ), '/' ) );
|
32 |
-
if (!defined('WPCF7CF_PLUGIN_DIR')) define( 'WPCF7CF_PLUGIN_DIR', untrailingslashit( dirname( WPCF7CF_PLUGIN ) ) );
|
33 |
-
|
34 |
-
function wpcf7cf_plugin_path( $path = '' ) {
|
35 |
-
return path_join( WPCF7CF_PLUGIN_DIR, trim( $path, '/' ) );
|
36 |
-
}
|
37 |
-
|
38 |
-
function wpcf7cf_plugin_url( $path = '' ) {
|
39 |
-
$url = plugins_url( $path, WPCF7CF_PLUGIN );
|
40 |
-
if ( is_ssl() && 'http:' == substr( $url, 0, 5 ) ) {
|
41 |
-
$url = 'https:' . substr( $url, 5 );
|
42 |
-
}
|
43 |
-
return $url;
|
44 |
-
}
|
45 |
-
|
46 |
-
if(file_exists(WPCF7CF_PLUGIN_DIR.'/pro/pro-functions.php')) {
|
47 |
-
if (!defined('WPCF7CF_IS_PRO')) define( 'WPCF7CF_IS_PRO', true );
|
48 |
-
require_once WPCF7CF_PLUGIN_DIR.'/pro/pro-functions.php';
|
49 |
-
} else {
|
50 |
-
if (!defined('WPCF7CF_IS_PRO')) define( 'WPCF7CF_IS_PRO', false );
|
51 |
-
}
|
52 |
-
|
53 |
-
require_once 'cf7cf.php';
|
54 |
-
require_once 'wpcf7cf-options.php';
|
55 |
-
|
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
|
8 |
Author URI: http://bdwm.be/
|
9 |
*/
|
10 |
|
24 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
25 |
*/
|
26 |
|
27 |
+
require_once 'init.php';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
init.php
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if (!defined('WPCF7CF_VERSION')) define( 'WPCF7CF_VERSION', '1.4' );
|
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 ) );
|
7 |
+
if (!defined('WPCF7CF_PLUGIN_NAME')) define( 'WPCF7CF_PLUGIN_NAME', trim( dirname( WPCF7CF_PLUGIN_BASENAME ), '/' ) );
|
8 |
+
if (!defined('WPCF7CF_PLUGIN_DIR')) define( 'WPCF7CF_PLUGIN_DIR', untrailingslashit( dirname( WPCF7CF_PLUGIN ) ) );
|
9 |
+
|
10 |
+
if(file_exists(WPCF7CF_PLUGIN_DIR.'/pro/pro-functions.php')) {
|
11 |
+
if (!defined('WPCF7CF_IS_PRO')) define( 'WPCF7CF_IS_PRO', true );
|
12 |
+
} else {
|
13 |
+
if (!defined('WPCF7CF_IS_PRO')) define( 'WPCF7CF_IS_PRO', false );
|
14 |
+
}
|
15 |
+
|
16 |
+
function wpcf7cf_plugin_path( $path = '' ) {
|
17 |
+
return path_join( WPCF7CF_PLUGIN_DIR, trim( $path, '/' ) );
|
18 |
+
}
|
19 |
+
|
20 |
+
function wpcf7cf_plugin_url( $path = '' ) {
|
21 |
+
$url = plugins_url( $path, WPCF7CF_PLUGIN );
|
22 |
+
if ( is_ssl() && 'http:' == substr( $url, 0, 5 ) ) {
|
23 |
+
$url = 'https:' . substr( $url, 5 );
|
24 |
+
}
|
25 |
+
return $url;
|
26 |
+
}
|
27 |
+
|
28 |
+
if (WPCF7CF_IS_PRO) {
|
29 |
+
require_once WPCF7CF_PLUGIN_DIR.'/pro/pro-functions.php';
|
30 |
+
}
|
31 |
+
|
32 |
+
require_once WPCF7CF_PLUGIN_DIR.'/cf7cf.php';
|
33 |
+
require_once WPCF7CF_PLUGIN_DIR.'/wpcf7cf-options.php';
|
js/scripts.js
CHANGED
@@ -4,23 +4,42 @@ var cf7signature_resized = 0; // for compatibility with contact-form-7-signature
|
|
4 |
|
5 |
var i=0;
|
6 |
var options = [];
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
// options.push(window['wpcf7cf_options_'+i]);
|
11 |
-
// continue;
|
12 |
-
// }
|
13 |
-
// break;
|
14 |
-
// }
|
15 |
|
16 |
$('.wpcf7').each(function(){
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
});
|
22 |
|
23 |
$(document).ready(function() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
function display_fields(unit_tag, wpcf7cf_conditions, wpcf7cf_settings) {
|
25 |
|
26 |
$current_form = $('#'+unit_tag);
|
@@ -44,119 +63,130 @@ var cf7signature_resized = 0; // for compatibility with contact-form-7-signature
|
|
44 |
|
45 |
var condition = wpcf7cf_conditions[i];
|
46 |
|
47 |
-
|
|
|
|
|
|
|
48 |
|
49 |
-
|
50 |
|
51 |
-
|
52 |
|
53 |
-
|
54 |
|
55 |
-
|
56 |
|
57 |
-
|
58 |
|
59 |
-
|
60 |
-
show = true;
|
61 |
-
}
|
62 |
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
condition.operator == 'not equals' && $option.val() == condition.if_value ||
|
72 |
-
condition.operator == 'not equals (regex)' && !regex_patt.test($option.val())
|
73 |
-
) {
|
74 |
-
show = false;
|
75 |
}
|
76 |
-
});
|
77 |
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
}
|
81 |
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
) {
|
98 |
-
|
99 |
}
|
100 |
-
} else if (
|
101 |
-
( condition.operator == 'equals' && $field.val() == condition.if_value ) ||
|
102 |
-
( condition.operator == 'not equals' && $field.val() != condition.if_value ) ||
|
103 |
-
( condition.operator == 'equals (regex)' && regex_patt.test($field.val()) ) ||
|
104 |
-
( condition.operator == 'not equals (regex)' && !regex_patt.test($field.val()) ) ||
|
105 |
-
( condition.operator == '>' && $field.val() > condition.if_value ) ||
|
106 |
-
( condition.operator == '<' && $field.val() < condition.if_value ) ||
|
107 |
-
( condition.operator == '>=' && $field.val() >= condition.if_value ) ||
|
108 |
-
( condition.operator == '<=' && $field.val() <= condition.if_value ) ||
|
109 |
-
( condition.operator == 'is empty' && $field.val() == '' ) ||
|
110 |
-
( condition.operator == 'not empty' && $field.val() != '' )
|
111 |
-
) {
|
112 |
-
$('#'+unit_tag+' #'+condition.then_field).removeClass('wpcf7cf-hidden');
|
113 |
-
}
|
114 |
|
115 |
|
116 |
-
|
117 |
|
118 |
-
|
119 |
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
var checked_value_index = $.inArray(condition.if_value, checked_values);
|
130 |
-
var value_index = $.inArray(condition.if_value, all_values);
|
131 |
-
|
132 |
-
if (
|
133 |
-
( condition.operator == 'is empty' && checked_values.length == 0 ) ||
|
134 |
-
( condition.operator == 'not empty' && checked_values.length > 0 )
|
135 |
-
) {
|
136 |
-
$('#'+unit_tag+' #'+condition.then_field).removeClass('wpcf7cf-hidden');
|
137 |
-
}
|
138 |
|
|
|
|
|
139 |
|
140 |
-
for(var ind=0; ind<checked_values.length; ind++) {
|
141 |
if (
|
142 |
-
(
|
143 |
-
(
|
144 |
-
( condition.operator == 'equals (regex)' && regex_patt.test(checked_values[ind]) ) ||
|
145 |
-
( condition.operator == 'not equals (regex)' && !regex_patt.test(checked_values[ind]) ) ||
|
146 |
-
( condition.operator == '>' && checked_values[ind] > condition.if_value ) ||
|
147 |
-
( condition.operator == '<' && checked_values[ind] < condition.if_value ) ||
|
148 |
-
( condition.operator == '>=' && checked_values[ind] >= condition.if_value ) ||
|
149 |
-
( condition.operator == '<=' && checked_values[ind] <= condition.if_value )
|
150 |
) {
|
151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
}
|
153 |
}
|
|
|
|
|
|
|
|
|
154 |
}
|
155 |
}
|
156 |
|
157 |
-
var show_animation = { "height": "show", "marginTop": "show", "marginBottom": "show", "paddingTop": "show", "paddingBottom": "show" };
|
158 |
-
var hide_animation = { "height": "hide", "marginTop": "hide", "marginBottom": "hide", "paddingTop": "hide", "paddingBottom": "hide" };
|
159 |
-
|
160 |
var animation_intime = parseInt(wpcf7cf_settings.animation_intime);
|
161 |
var animation_outtime = parseInt(wpcf7cf_settings.animation_outtime);
|
162 |
|
@@ -169,9 +199,26 @@ var cf7signature_resized = 0; // for compatibility with contact-form-7-signature
|
|
169 |
$group = $(this);
|
170 |
if ($group.is(':animated')) $group.finish(); // stop any current animations on the group
|
171 |
if ($group.css('display') == 'none' && !$group.hasClass('wpcf7cf-hidden')) {
|
172 |
-
$group.
|
|
|
|
|
|
|
|
|
173 |
} else if ($group.css('display') != 'none' && $group.hasClass('wpcf7cf-hidden')) {
|
174 |
-
$group.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
}
|
176 |
});
|
177 |
|
@@ -188,7 +235,7 @@ var cf7signature_resized = 0; // for compatibility with contact-form-7-signature
|
|
188 |
|
189 |
display_fields(unit_tag, conditions, settings);
|
190 |
|
191 |
-
$('#'+unit_tag+' input, #'+unit_tag+' select, #'+unit_tag+' textarea').on('input paste change',{unit_tag:unit_tag, conditions:conditions, settings:settings}, function(e) {
|
192 |
clearTimeout(timeout);
|
193 |
timeout = setTimeout(display_fields, 100, e.data.unit_tag, e.data.conditions, e.data.settings);
|
194 |
});
|
@@ -197,7 +244,6 @@ var cf7signature_resized = 0; // for compatibility with contact-form-7-signature
|
|
197 |
$('#'+unit_tag+' form').on('reset', {unit_tag:unit_tag, conditions:conditions, settings:settings}, function(e) {
|
198 |
setTimeout(display_fields, 200, e.data.unit_tag, e.data.conditions, e.data.settings);
|
199 |
});
|
200 |
-
|
201 |
}
|
202 |
|
203 |
// Also add hidden fields in case a form gets submitted without any input:
|
@@ -242,7 +288,7 @@ var cf7signature_resized = 0; // for compatibility with contact-form-7-signature
|
|
242 |
typeof xhr.responseJSON.into !== 'undefined' &&
|
243 |
xhr.responseJSON.mailSent === true)
|
244 |
{
|
245 |
-
$( xhr.responseJSON.into + ' input, '+xhr.responseJSON.into+' select, ' + xhr.responseJSON.into + ' textarea' ).change();
|
246 |
}
|
247 |
});
|
248 |
|
@@ -256,3 +302,14 @@ var cf7signature_resized = 0; // for compatibility with contact-form-7-signature
|
|
256 |
};
|
257 |
|
258 |
})( jQuery );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
var i=0;
|
6 |
var options = [];
|
7 |
+
|
8 |
+
var show_animation = { "height": "show", "marginTop": "show", "marginBottom": "show", "paddingTop": "show", "paddingBottom": "show" };
|
9 |
+
var hide_animation = { "height": "hide", "marginTop": "hide", "marginBottom": "hide", "paddingTop": "hide", "paddingBottom": "hide" };
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
$('.wpcf7').each(function(){
|
12 |
+
|
13 |
+
// Bug fix thanks to 972 creative (@toddedelman) https://wordpress.org/support/topic/conditional-fields-not-opening-using-radio-buttons/#post-10442923
|
14 |
+
|
15 |
+
var $this = $(this);
|
16 |
+
var options_element = $this.find('input[name="_wpcf7cf_options"]').eq(0);
|
17 |
+
if (options_element.length) {
|
18 |
+
var value = options_element.val();
|
19 |
+
if (value) {
|
20 |
+
form_options = JSON.parse(value);
|
21 |
+
form_options.unit_tag = $this.attr('id');
|
22 |
+
options.push(form_options);
|
23 |
+
}
|
24 |
+
}
|
25 |
});
|
26 |
|
27 |
$(document).ready(function() {
|
28 |
+
|
29 |
+
//wpcf7pro-togglebutton
|
30 |
+
|
31 |
+
$('.wpcf7cf-togglebutton').click(function() {
|
32 |
+
$this = $(this);
|
33 |
+
if ($this.text() == $this.data('val-1')) {
|
34 |
+
$this.text($this.data('val-2'));
|
35 |
+
$this.val($this.data('val-2'));
|
36 |
+
} else {
|
37 |
+
$this.text($this.data('val-1'));
|
38 |
+
$this.val($this.data('val-1'));
|
39 |
+
}
|
40 |
+
});
|
41 |
+
|
42 |
+
|
43 |
function display_fields(unit_tag, wpcf7cf_conditions, wpcf7cf_settings) {
|
44 |
|
45 |
$current_form = $('#'+unit_tag);
|
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 |
|
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 |
});
|
224 |
|
235 |
|
236 |
display_fields(unit_tag, conditions, settings);
|
237 |
|
238 |
+
$('#'+unit_tag+' input, #'+unit_tag+' select, #'+unit_tag+' textarea, #'+unit_tag+' button').on('input paste change click',{unit_tag:unit_tag, conditions:conditions, settings:settings}, function(e) {
|
239 |
clearTimeout(timeout);
|
240 |
timeout = setTimeout(display_fields, 100, e.data.unit_tag, e.data.conditions, e.data.settings);
|
241 |
});
|
244 |
$('#'+unit_tag+' form').on('reset', {unit_tag:unit_tag, conditions:conditions, settings:settings}, function(e) {
|
245 |
setTimeout(display_fields, 200, e.data.unit_tag, e.data.conditions, e.data.settings);
|
246 |
});
|
|
|
247 |
}
|
248 |
|
249 |
// Also add hidden fields in case a form gets submitted without any input:
|
288 |
typeof xhr.responseJSON.into !== 'undefined' &&
|
289 |
xhr.responseJSON.mailSent === true)
|
290 |
{
|
291 |
+
$( xhr.responseJSON.into + ' input, '+xhr.responseJSON.into+' select, ' + xhr.responseJSON.into + ' textarea, ' + xhr.responseJSON.into + ' button' ).change();
|
292 |
}
|
293 |
});
|
294 |
|
302 |
};
|
303 |
|
304 |
})( jQuery );
|
305 |
+
|
306 |
+
|
307 |
+
/* Demo Code. */
|
308 |
+
|
309 |
+
/* Clear values of hidden fields */
|
310 |
+
// jQuery('[data-class="wpcf7cf_group"]').on('wpcf7cf_hide_group', function(e) {
|
311 |
+
// $group = jQuery(e.target);
|
312 |
+
// $group.find('input').not(':checkbox, :button, :submit, :reset, :hidden').val('');
|
313 |
+
// $group.find('option').removeAttr('selected');
|
314 |
+
// $group.find(':checkbox').removeAttr('checked');
|
315 |
+
// });
|
js/scripts_admin.js
CHANGED
@@ -1,18 +1,51 @@
|
|
1 |
/**
|
2 |
* Created by jules on 7/17/2015.
|
3 |
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
if (_wpcf7 == null) { var _wpcf7 = wpcf7}; // wpcf7 4.8 fix
|
6 |
|
7 |
var old_compose = _wpcf7.taggen.compose;
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
(function($) {
|
10 |
|
|
|
|
|
|
|
|
|
11 |
// ...before overwriting the jQuery extension point
|
12 |
_wpcf7.taggen.compose = function(tagType, $form)
|
13 |
{
|
14 |
|
15 |
-
|
16 |
|
17 |
// original behavior - use function.apply to preserve context
|
18 |
var ret = old_compose.apply(this, arguments);
|
@@ -23,18 +56,25 @@ var old_compose = _wpcf7.taggen.compose;
|
|
23 |
if (tagType== 'group') ret += "[/group]";
|
24 |
// END
|
25 |
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
28 |
|
29 |
-
|
|
|
30 |
|
31 |
-
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
return false;
|
36 |
|
37 |
-
|
|
|
|
|
|
|
|
|
38 |
|
39 |
$('#wpcf7cf-add-button').click(function(){
|
40 |
|
@@ -49,35 +89,63 @@ var old_compose = _wpcf7.taggen.compose;
|
|
49 |
}
|
50 |
|
51 |
function add_condition_fields() {
|
52 |
-
|
53 |
-
$('<div class="entry" id="entry-'+index+'">'+($('#wpcf7cf-new-entry').html().replace(/{id}/g, index))+'</div>').prependTo('#wpcf7cf-entries').append($delete_button);
|
54 |
-
$delete_button.click(function(){
|
55 |
-
$(this).parent().remove();
|
56 |
-
return false;
|
57 |
-
});
|
58 |
index++;
|
59 |
-
|
60 |
return (index-1);
|
61 |
}
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
function import_condition_fields() {
|
|
|
|
|
|
|
64 |
var lines = $('#wpcf7cf-settings-text').val().split(/\r?\n/);
|
65 |
-
|
|
|
|
|
|
|
66 |
|
67 |
var str = lines[i];
|
68 |
|
69 |
var match = regex.exec(str);
|
70 |
|
71 |
-
if (match
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
-
|
74 |
|
75 |
-
|
76 |
-
$('#entry-'+id+' .operator').val(match[2]);
|
77 |
-
$('#entry-'+id+' .if-value').val(match[3]);
|
78 |
-
$('#entry-'+id+' .then-field-select').val(match[4]);
|
79 |
|
80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
}
|
82 |
}
|
83 |
|
@@ -91,16 +159,25 @@ var old_compose = _wpcf7.taggen.compose;
|
|
91 |
$('#wpcf7cf-settings-text').val('');
|
92 |
$('#wpcf7cf-entries .entry').each(function() {
|
93 |
var $entry = $(this);
|
94 |
-
var line = '
|
95 |
-
|
96 |
-
|
97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
$('#wpcf7cf-settings-text').val($('#wpcf7cf-settings-text').val() + line + "\n" ).select();
|
99 |
});
|
100 |
return false;
|
101 |
});
|
102 |
|
103 |
-
|
104 |
|
105 |
$('#add-fields').click(function() {
|
106 |
import_condition_fields();
|
@@ -122,79 +199,111 @@ var old_compose = _wpcf7.taggen.compose;
|
|
122 |
});
|
123 |
|
124 |
function update_entries() {
|
125 |
-
$('.if-value')
|
126 |
-
|
127 |
-
|
128 |
-
$
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
$
|
|
|
|
|
134 |
}
|
135 |
});
|
|
|
|
|
|
|
|
|
136 |
}
|
137 |
|
138 |
-
|
139 |
-
|
140 |
-
{
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
156 |
}
|
157 |
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
$
|
|
|
|
|
|
|
|
|
170 |
return false;
|
171 |
-
}
|
172 |
-
|
173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
return false;
|
175 |
-
}
|
176 |
-
open: function(e,ui) {
|
177 |
-
$el = $(e.target);
|
178 |
-
var styledTerm = termTemplate.replace('%s', $el.val());
|
179 |
-
|
180 |
-
$('.ui-autocomplete').find('em').each(function() {
|
181 |
-
var me = $(this);
|
182 |
-
me.html( me.text().replace($el.val(), styledTerm) );
|
183 |
-
});
|
184 |
-
}
|
185 |
-
}).each(function() {
|
186 |
-
$(this).autocomplete( "instance" )._renderItem = function( ul, item ) {
|
187 |
-
return $("<li>")
|
188 |
-
.append("<div><em>" + item.label + "</em><br><em>" + item.desc + "</em></div>")
|
189 |
-
.appendTo(ul);
|
190 |
-
}
|
191 |
-
});
|
192 |
|
193 |
-
|
|
|
|
|
|
|
|
|
194 |
|
195 |
-
|
196 |
-
|
197 |
-
|
|
|
|
|
|
|
|
|
|
|
198 |
|
199 |
// ------------------------------------
|
200 |
// OPTIONS PAGE
|
1 |
/**
|
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);
|
56 |
if (tagType== 'group') ret += "[/group]";
|
57 |
// END
|
58 |
|
59 |
+
if (tagType== 'togglebutton') {
|
60 |
+
$val1 = $('#tag-generator-panel-togglebutton-value-1');
|
61 |
+
$val2 = $('#tag-generator-panel-togglebutton-value-2');
|
62 |
+
var val1 = $val1.val();
|
63 |
+
var val2 = $val2.val();
|
64 |
|
65 |
+
if (val1 == "") val1 = $val1.data('default');
|
66 |
+
if (val2 == "") val2 = $val2.data('default');
|
67 |
|
68 |
+
str_val = ' "'+val1+'" "'+val2+'"';
|
69 |
|
70 |
+
ret = ret.replace(']', str_val+']');
|
71 |
+
}
|
|
|
72 |
|
73 |
+
return ret;
|
74 |
+
};
|
75 |
+
|
76 |
+
var index = $('#wpcf7cf-entries .entry').length;
|
77 |
+
var index_and = 0;
|
78 |
|
79 |
$('#wpcf7cf-add-button').click(function(){
|
80 |
|
89 |
}
|
90 |
|
91 |
function add_condition_fields() {
|
92 |
+
$('<div class="entry" id="entry-'+index+'">'+(wpcf7cf_new_entry_html.replace(/{id}/g, index))+'</div>').appendTo('#wpcf7cf-entries');
|
|
|
|
|
|
|
|
|
|
|
93 |
index++;
|
94 |
+
update_entries();
|
95 |
return (index-1);
|
96 |
}
|
97 |
|
98 |
+
function add_and_condition_fields(id) {
|
99 |
+
// $('#entry-'+id+' .wpcf7cf-and-rules').eq(0).append($wpcf7cf_new_and_rule.clone());
|
100 |
+
$('#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+']'));
|
101 |
+
index_and++;
|
102 |
+
return (index_and-1);
|
103 |
+
}
|
104 |
+
|
105 |
function import_condition_fields() {
|
106 |
+
|
107 |
+
$if_values = $('.if-value');
|
108 |
+
|
109 |
var lines = $('#wpcf7cf-settings-text').val().split(/\r?\n/);
|
110 |
+
|
111 |
+
var id = -1;
|
112 |
+
|
113 |
+
for (var i = 0; i<lines.length; i++) {
|
114 |
|
115 |
var str = lines[i];
|
116 |
|
117 |
var match = regex.exec(str);
|
118 |
|
119 |
+
if (match != null) {
|
120 |
+
|
121 |
+
index_and = 0; // reset this for each first condition (This one has and_index [0]).
|
122 |
+
|
123 |
+
id = add_condition_fields();
|
124 |
+
|
125 |
+
$('#entry-'+id+' .then-field-select').val(match[1]);
|
126 |
+
$('#entry-'+id+' .if-field-select').val(match[2]);
|
127 |
+
$('#entry-'+id+' .operator').val(match[3]);
|
128 |
+
$('#entry-'+id+' .if-value').val(match[4]);
|
129 |
+
|
130 |
+
index_and = 1; // the next and condition will gave and_index[1];
|
131 |
+
|
132 |
+
regex.lastIndex = 0;
|
133 |
+
|
134 |
+
}
|
135 |
+
|
136 |
+
match = regex_and.exec(str);
|
137 |
|
138 |
+
if (match != null && id != -1) {
|
139 |
|
140 |
+
var and_id = add_and_condition_fields(id);
|
|
|
|
|
|
|
141 |
|
142 |
+
$('#entry-'+id+' .wpcf7cf-and-rule:last-child .if-field-select').val(match[1]);
|
143 |
+
$('#entry-'+id+' .wpcf7cf-and-rule:last-child .operator').val(match[2]);
|
144 |
+
$('#entry-'+id+' .wpcf7cf-and-rule:last-child .if-value').val(match[3]);
|
145 |
+
|
146 |
+
regex_and.lastIndex = 0;
|
147 |
+
|
148 |
+
}
|
149 |
}
|
150 |
}
|
151 |
|
159 |
$('#wpcf7cf-settings-text').val('');
|
160 |
$('#wpcf7cf-entries .entry').each(function() {
|
161 |
var $entry = $(this);
|
162 |
+
var line = 'show [' + $entry.find('.then-field-select').val() + ']';
|
163 |
+
var text_indent = line.length-3;
|
164 |
+
$entry.find('.wpcf7cf-and-rule').each(function(i) {
|
165 |
+
$and_rule = $(this);
|
166 |
+
if (i>0) {
|
167 |
+
|
168 |
+
line += '\n'+' '.repeat(text_indent)+'and';
|
169 |
+
|
170 |
+
}
|
171 |
+
line += ' if [' + $and_rule.find('.if-field-select').val() + ']'
|
172 |
+
+ ' ' + $and_rule.find('.operator').val()
|
173 |
+
+ ' "' + $and_rule.find('.if-value').val() + '"';
|
174 |
+
});
|
175 |
$('#wpcf7cf-settings-text').val($('#wpcf7cf-settings-text').val() + line + "\n" ).select();
|
176 |
});
|
177 |
return false;
|
178 |
});
|
179 |
|
180 |
+
$if_values = $('.if-value');
|
181 |
|
182 |
$('#add-fields').click(function() {
|
183 |
import_condition_fields();
|
199 |
});
|
200 |
|
201 |
function update_entries() {
|
202 |
+
$if_values = $('.if-value');
|
203 |
+
init_autocomplete();
|
204 |
+
$if_values.css({'visibility':'visible'});
|
205 |
+
$if_values.autocomplete( "disable" );
|
206 |
+
|
207 |
+
$('#wpcf7cf-entries .wpcf7cf-and-rule').each(function() {
|
208 |
+
var $and_rule = $(this);
|
209 |
+
if ($and_rule.find('.operator').eq(0).val() === 'is empty' || $and_rule.find('.operator').eq(0).val() === 'not empty') {
|
210 |
+
$and_rule.find('.if-value').eq(0).css({'visibility':'hidden'});
|
211 |
+
} else if ($and_rule.find('.operator').eq(0).val().endsWith('(regex)')) {
|
212 |
+
$and_rule.find('.if-value').eq(0).autocomplete( "enable" );
|
213 |
}
|
214 |
});
|
215 |
+
|
216 |
+
scale_and_button();
|
217 |
+
|
218 |
+
set_events();
|
219 |
}
|
220 |
|
221 |
+
function init_autocomplete() {
|
222 |
+
|
223 |
+
$if_values.autocomplete({
|
224 |
+
disabled: true,
|
225 |
+
source: function(request, response) {
|
226 |
+
var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
|
227 |
+
response($.grep(regexes, function(value) {
|
228 |
+
return matcher.test(value.label || value.value || value) || matcher.test(value.desc);
|
229 |
+
}));
|
230 |
+
},
|
231 |
+
focus: function( event, ui ) {
|
232 |
+
$( event.target ).val( ui.item.desc );
|
233 |
+
return false;
|
234 |
+
},
|
235 |
+
select: function( event, ui ) {
|
236 |
+
$( event.target ).val( ui.item.desc );
|
237 |
+
return false;
|
238 |
+
},
|
239 |
+
open: function(e,ui) {
|
240 |
+
$el = $(e.target);
|
241 |
+
var styledTerm = termTemplate.replace('%s', $el.val());
|
242 |
+
|
243 |
+
$('.ui-autocomplete').find('em').each(function() {
|
244 |
+
var me = $(this);
|
245 |
+
me.html( me.text().replace($el.val(), styledTerm) );
|
246 |
+
});
|
247 |
+
},
|
248 |
+
minLength: 0
|
249 |
+
}).each(function() {
|
250 |
+
$(this).autocomplete( "instance" )._renderItem = function( ul, item ) {
|
251 |
+
return $("<li>")
|
252 |
+
.append("<div><em>" + item.label + "</em><br><em>" + item.desc + "</em></div>")
|
253 |
+
.appendTo(ul);
|
254 |
+
}
|
255 |
+
});
|
256 |
+
$if_values.on('focus', function() {
|
257 |
+
$(this).autocomplete("search");
|
258 |
+
});
|
259 |
}
|
260 |
|
261 |
+
update_entries();
|
262 |
+
|
263 |
+
function set_events() { // called at the end of update_entries
|
264 |
+
|
265 |
+
$('.wpcf7cf-and-rules').sortable();
|
266 |
+
|
267 |
+
$('.and-button').off('click').click(function() {
|
268 |
+
$this = $(this);
|
269 |
+
$andblock = $this.closest('.wpcf7cf-and-rule');
|
270 |
+
$andblocks_container = $this.closest('.wpcf7cf-and-rules');
|
271 |
+
next_index = $andblocks_container.data('next-index');
|
272 |
+
$andblocks_container.data('next-index',next_index+1);
|
273 |
+
var and_i = next_index;
|
274 |
+
clone_html = $andblock.get(0).outerHTML.replace(/wpcf7cf_options\[([0-9]*)\]\[and_rules\]\[([0-9]*)\]/g, 'wpcf7cf_options[$1][and_rules]['+and_i+']');
|
275 |
+
$andblock.after(clone_html);
|
276 |
+
update_entries();
|
277 |
return false;
|
278 |
+
});
|
279 |
+
|
280 |
+
$('.delete-button').off('click').click(function(){
|
281 |
+
$and_rule = $(this).closest('.wpcf7cf-and-rule');
|
282 |
+
if ($and_rule.siblings().length > 0) {
|
283 |
+
$and_rule.remove();
|
284 |
+
} else {
|
285 |
+
$and_rule[0].closest('.entry').remove();
|
286 |
+
}
|
287 |
+
|
288 |
+
update_entries();
|
289 |
+
|
290 |
return false;
|
291 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
292 |
|
293 |
+
$('.operator').off('change').change(function() {
|
294 |
+
update_entries();
|
295 |
+
return false;
|
296 |
+
});
|
297 |
+
}
|
298 |
|
299 |
+
function scale_and_button() {
|
300 |
+
$('.wpcf7cf-and-rule:first-child .and-button').each(function(){
|
301 |
+
$and_button = $(this);
|
302 |
+
num_and_rules = $and_button.closest('.wpcf7cf-and-rule').siblings().length+1;
|
303 |
+
var height = (34*num_and_rules-12)+'px';
|
304 |
+
$and_button.css({'height':height,'line-height':height});
|
305 |
+
});
|
306 |
+
}
|
307 |
|
308 |
// ------------------------------------
|
309 |
// OPTIONS PAGE
|
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
|
9 |
-
Stable tag: 1.
|
10 |
License: GPLv2 or later
|
11 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
12 |
|
@@ -17,19 +17,14 @@ Adds conditional logic to Contact Form 7.
|
|
17 |
This plugin adds conditional logic to [Contact Form 7](https://wordpress.org/plugins/contact-form-7/).
|
18 |
|
19 |
If you edit your CF7 form, you will see an additional tag called "Conditional fields Group". Everything you put between the start and end tag will be hidden by default.
|
20 |
-
After you added the field group(s),
|
21 |
-
Then you should go to the "Conditional fields" tab to create one or more conditions that will make the group(s) appear.
|
22 |
|
23 |
= How to use it =
|
24 |
|
25 |
-
|
26 |
|
27 |
== Main/ New features ==
|
28 |
|
29 |
-
= Compatible with Contact Form 7 Multi-Step Forms =
|
30 |
-
|
31 |
-
Conditional Fields for Contact Form 7 is now fully compatible with <a target="_blank" href="https://wordpress.org/plugins/contact-form-7-multi-step-module/">Contact Form 7 Multi-Step Forms</a>
|
32 |
-
|
33 |
= Support for required fields =
|
34 |
|
35 |
Required fields can be used inside hidden groups without causing validation problems.
|
@@ -60,17 +55,17 @@ Example email:
|
|
60 |
|
61 |
= Advanced =
|
62 |
|
63 |
-
Advanced users can
|
64 |
|
65 |
== Installation ==
|
66 |
|
67 |
Please follow the [standard installation procedure for WordPress plugins](http://codex.wordpress.org/Managing_Plugins#Installing_Plugins).
|
68 |
|
69 |
-
Follow [this tutorial](
|
70 |
|
71 |
== Frequently Asked Questions ==
|
72 |
|
73 |
-
= Email message is not showing the correct values =
|
74 |
|
75 |
<strong>All field names should be unique</strong>
|
76 |
|
@@ -99,55 +94,21 @@ Check if your theme is calling the `wp_footer()` function. Typically this functi
|
|
99 |
The conditional fields javascript code is loaded during wp_footer, so a call to this function is crucial. If there is no such call in your theme, go to your theme's footer.php file and add this code right before the closing `</body>` tag:
|
100 |
`<?php wp_footer(); ?>`
|
101 |
|
102 |
-
= How do i show fields based on multiple conditions? (AND, OR, NAND, NOR) =
|
103 |
-
|
104 |
-
<strong>if a=1 AND b=2 then, show [group x]</strong>
|
105 |
-
|
106 |
-
You will need to create nested groups for the number of conditions, so your form might look like this:
|
107 |
-
|
108 |
-
`[select a "1" "2" "3"]
|
109 |
-
[select b "1" "2" "3"]
|
110 |
-
[group x-1][group x-2]TADA![/group][/group]`
|
111 |
-
|
112 |
-
and use these conditions
|
113 |
-
|
114 |
-
`if [a] equals "1" then show [x-1]
|
115 |
-
if [b] equals "2" then show [x-2]`
|
116 |
-
|
117 |
-
<strong>if a=1 OR b=2 then, show [group x]</strong>
|
118 |
-
|
119 |
-
This is more straightforward, as OR conditions are assumed. Giving this form:
|
120 |
-
|
121 |
-
`[select a "1" "2" "3"]
|
122 |
-
[select b "1" "2" "3"]
|
123 |
-
[group x]TADA![/group]`
|
124 |
-
|
125 |
-
You can simply use these conditions:
|
126 |
-
|
127 |
-
`if [a] equals "1" then show [x]
|
128 |
-
if [b] equals "2" then show [x]`
|
129 |
-
|
130 |
-
<strong>if a=1 NAND b=2 then, show [group x]</strong>
|
131 |
-
|
132 |
-
Same form as OR, but just use "not equals" instead of "equals":
|
133 |
-
|
134 |
-
`if [a] not equals "1" then show [x]
|
135 |
-
if [b] not equals "2" then show [x]`
|
136 |
-
|
137 |
-
<strong>if a=1 NOR b=2 then, show [group x]</strong>
|
138 |
-
|
139 |
-
Same form as AND, but just use "not equals" instead of "equals":
|
140 |
-
|
141 |
-
`if [a] not equals "1" then show [x-1]
|
142 |
-
if [b] not equals "2" then show [x-2]`
|
143 |
-
|
144 |
== Screenshots ==
|
145 |
|
146 |
-
1.
|
147 |
-
2.
|
148 |
|
149 |
== Changelog ==
|
150 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
= 1.3.4 =
|
152 |
* small fix (https://wordpress.org/support/topic/wpcf7_contactform-object-is-no-longer-accessible/)
|
153 |
|
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
|
10 |
License: GPLv2 or later
|
11 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
12 |
|
17 |
This plugin adds conditional logic to [Contact Form 7](https://wordpress.org/plugins/contact-form-7/).
|
18 |
|
19 |
If you edit your CF7 form, you will see an additional tag called "Conditional fields Group". Everything you put between the start and end tag will be hidden by default.
|
20 |
+
After you have added the field group(s), click Save and go to the "Conditional fields" tab to create one or more conditions that will make the group(s) appear.
|
|
|
21 |
|
22 |
= How to use it =
|
23 |
|
24 |
+
[Follow this tutorial](https://conditional-fields-cf7.bdwm.be/conditional-fields-for-contact-form-7-tutorial/)
|
25 |
|
26 |
== Main/ New features ==
|
27 |
|
|
|
|
|
|
|
|
|
28 |
= Support for required fields =
|
29 |
|
30 |
Required fields can be used inside hidden groups without causing validation problems.
|
55 |
|
56 |
= Advanced =
|
57 |
|
58 |
+
Advanced users can code up the conditions as plain text instead of using the select boxes, using the import/export feature.
|
59 |
|
60 |
== Installation ==
|
61 |
|
62 |
Please follow the [standard installation procedure for WordPress plugins](http://codex.wordpress.org/Managing_Plugins#Installing_Plugins).
|
63 |
|
64 |
+
Follow [this tutorial](https://conditional-fields-cf7.bdwm.be/conditional-fields-for-contact-form-7-tutorial/) if you are not sure how to use the plugin.
|
65 |
|
66 |
== Frequently Asked Questions ==
|
67 |
|
68 |
+
= Email message is not showing the correct values / Wrong values are submitted =
|
69 |
|
70 |
<strong>All field names should be unique</strong>
|
71 |
|
94 |
The conditional fields javascript code is loaded during wp_footer, so a call to this function is crucial. If there is no such call in your theme, go to your theme's footer.php file and add this code right before the closing `</body>` tag:
|
95 |
`<?php wp_footer(); ?>`
|
96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
== Screenshots ==
|
98 |
|
99 |
+
1. Conditional fields in action
|
100 |
+
2. Defining rules to show/hide groups of input elements in the backend interface
|
101 |
|
102 |
== Changelog ==
|
103 |
|
104 |
+
= 1.4 =
|
105 |
+
* (08-15-18) Added basic drag and drop functionality to the back-end so conditional rules can be rearranged.
|
106 |
+
* (08-12-18) Added possibility to create inline groups by adding the option inline. Example: `[group my-group inline] ... [/group]`
|
107 |
+
* (08-12-18) Added property clear_on_hide to clear all fields within a group the moment the group gets hidden. Example: `[group my-group clear_on_hide] ... [/group]`
|
108 |
+
* (08-12-18) Added AND conditions and added a bunch of other options in the PRO version (should be released very soon now)
|
109 |
+
* (08-12-18) Bug fix thanks to Aurovrata Venet (@aurovrata) https://wordpress.org/support/topic/bug-plugin-overwrite-cf7-hidden-fields/
|
110 |
+
* (06-28-18) Bug fix thanks to 972 creative (@toddedelman) https://wordpress.org/support/topic/conditional-fields-not-opening-using-radio-buttons/#post-10442923
|
111 |
+
|
112 |
= 1.3.4 =
|
113 |
* small fix (https://wordpress.org/support/topic/wpcf7_contactform-object-is-no-longer-accessible/)
|
114 |
|
screenshot-1.png
DELETED
Binary file
|
screenshot-2.png
DELETED
Binary file
|
style.css
CHANGED
@@ -1,4 +1,4 @@
|
|
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 |
-
}
|
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 |
+
}
|
tg_pane_group.php
CHANGED
@@ -10,6 +10,16 @@
|
|
10 |
<td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
|
11 |
</tr>
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
</tbody>
|
14 |
</table>
|
15 |
</fieldset>
|
10 |
<td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
|
11 |
</tr>
|
12 |
|
13 |
+
<tr>
|
14 |
+
<th scope="row"><label for="clear_on_hide"><?php echo esc_html( __( 'Clear on hide', 'contact-form-7' ) ); ?></label></th>
|
15 |
+
<td><input type="checkbox" name="clear_on_hide" class="option" id="clear_on_hide" /></td>
|
16 |
+
</tr>
|
17 |
+
|
18 |
+
<tr>
|
19 |
+
<th scope="row"><label for="inline"><?php echo esc_html( __( 'Inline', 'contact-form-7' ) ); ?></label></th>
|
20 |
+
<td><input type="checkbox" name="inline" class="option" id="inline" /></td>
|
21 |
+
</tr>
|
22 |
+
|
23 |
</tbody>
|
24 |
</table>
|
25 |
</fieldset>
|
wpcf7cf-options.php
CHANGED
@@ -34,17 +34,13 @@ if ($wpcf7cf_options['wpcf7cf_settings_saved'] == 0) {
|
|
34 |
$wpcf7cf_options = $wpcf7cf_default_options;
|
35 |
}
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
add_action('ninja_forms_display_after_field_function','wpcf7cf_wrap_input_field_after');
|
40 |
-
|
41 |
-
function wpcf7cf_wrap_input_field_before() { echo '<div class="resizable_input_wrapper">'; }
|
42 |
-
function wpcf7cf_wrap_input_field_after() { echo '</div>'; }
|
43 |
|
44 |
add_action( 'admin_enqueue_scripts', 'wpcf7cf_load_page_options_wp_admin_style' );
|
45 |
function wpcf7cf_load_page_options_wp_admin_style() {
|
46 |
-
wp_register_style( '
|
47 |
-
wp_enqueue_style( '
|
48 |
}
|
49 |
|
50 |
|
@@ -63,7 +59,7 @@ function wpcf7cf_options_page() {
|
|
63 |
|
64 |
if (isset($_POST['reset'])) {
|
65 |
echo '<div id="message" class="updated fade"><p><strong>Settings restored to defaults</strong></p></div>';
|
66 |
-
} else if ($_REQUEST['settings-updated']) {
|
67 |
echo '<div id="message" class="updated fade"><p><strong>Settings updated</strong></p></div>';
|
68 |
}
|
69 |
|
@@ -215,7 +211,7 @@ function wpcf7cf_input_field($slug, $args) {
|
|
215 |
?>
|
216 |
<div class="option-line">
|
217 |
<?php if ($label_editable) { ?>
|
218 |
-
<span class="label"><input type="text" data-default-value="<?php echo $label ?>" value="<?php echo $wpcf7cf_options[$slug.'_label'] ?>" id="<?php echo WPCF7CF_OPTIONS.'_'.$slug.'_label' ?>" name="<?php echo WPCF7CF_OPTIONS.'['.$slug.'_label]' ?>"></span>
|
219 |
<?php } else { ?>
|
220 |
<span class="label"><?php echo $label ?></span>
|
221 |
<?php } ?>
|
34 |
$wpcf7cf_options = $wpcf7cf_default_options;
|
35 |
}
|
36 |
|
37 |
+
// LINE 37: removed some ninja_forms related code. Not sure what it was doing here. Keep this reminder here for a while in case problems pop up.
|
38 |
+
// Remove in future update. (Jules 17/02/2018)
|
|
|
|
|
|
|
|
|
39 |
|
40 |
add_action( 'admin_enqueue_scripts', 'wpcf7cf_load_page_options_wp_admin_style' );
|
41 |
function wpcf7cf_load_page_options_wp_admin_style() {
|
42 |
+
wp_register_style( 'wpcf7cf_admin_css', plugins_url('admin-style.css',__FILE__), false, WPCF7CF_VERSION );
|
43 |
+
wp_enqueue_style( 'wpcf7cf_admin_css' );
|
44 |
}
|
45 |
|
46 |
|
59 |
|
60 |
if (isset($_POST['reset'])) {
|
61 |
echo '<div id="message" class="updated fade"><p><strong>Settings restored to defaults</strong></p></div>';
|
62 |
+
} else if (isset($_REQUEST['settings-updated'])) {
|
63 |
echo '<div id="message" class="updated fade"><p><strong>Settings updated</strong></p></div>';
|
64 |
}
|
65 |
|
211 |
?>
|
212 |
<div class="option-line">
|
213 |
<?php if ($label_editable) { ?>
|
214 |
+
<span class="label editable"><input type="text" data-default-value="<?php echo $label ?>" value="<?php echo $wpcf7cf_options[$slug.'_label'] ?>" id="<?php echo WPCF7CF_OPTIONS.'_'.$slug.'_label' ?>" name="<?php echo WPCF7CF_OPTIONS.'['.$slug.'_label]' ?>"></span>
|
215 |
<?php } else { ?>
|
216 |
<span class="label"><?php echo $label ?></span>
|
217 |
<?php } ?>
|