Skip to content

Commit 31bf958

Browse files
committed
= 2.1 (2022-01-27) =
* Tested up to wp 5.9 * Scroll success message into view after successful form submission. [GH Issue 90](#90) * Small changes [GH PR 86](#86) * Make 'change' event bubble up [GH PR 88](#88)
1 parent 8e59499 commit 31bf958

File tree

12 files changed

+76
-75
lines changed

12 files changed

+76
-75
lines changed

admin.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ function wpcf7cf_editor_panel_conditional($form) {
9393

9494
$wpcf7cf_entries = CF7CF::getConditions($form_id);
9595

96-
9796
$wpcf7cf_entries = array_values($wpcf7cf_entries);
9897

9998
?>
@@ -176,7 +175,7 @@ function wpcf7cf_after_save($contact_form) {
176175
function wpcf7cf_save_contact_form( $contact_form )
177176
{
178177

179-
if ( ! isset( $_POST['wpcf7cf-settings-text'] ) ) {
178+
if ( ! isset( $_POST ) || empty( $_POST ) || ! isset( $_POST['wpcf7cf-settings-text'] ) ) {
180179
return;
181180
}
182181
$post_id = $contact_form->id();

cf7cf.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ public static function parse_conditions($string, $format='array') {
331331
* load the conditions from the form's post_meta
332332
*
333333
* @param string $form_id
334-
* @return void
334+
* @return array
335335
*/
336336
public static function getConditions($form_id) {
337337
// make sure conditions are an array.

contact-form-7-conditional-fields.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Plugin URI: http://bdwm.be/
55
* Description: Adds support for conditional fields to Contact Form 7. This plugin depends on Contact Form 7.
66
* Author: Jules Colle
7-
* Version: 2.0.9
7+
* Version: 2.1
88
* Author URI: http://bdwm.be/
99
* Text Domain: cf7-conditional-fields
1010
* License: GPL v2 or later

init.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
if (!defined('WPCF7CF_VERSION')) define( 'WPCF7CF_VERSION', '2.0.9' );
3+
if (!defined('WPCF7CF_VERSION')) define( 'WPCF7CF_VERSION', '2.1' );
44
if (!defined('WPCF7CF_CF7_MIN_VERSION')) define( 'WPCF7CF_CF7_MIN_VERSION', '5.4' );
55
if (!defined('WPCF7CF_CF7_MAX_VERSION')) define( 'WPCF7CF_CF7_MAX_VERSION', '5.5.4' );
66
if (!defined('WPCF7CF_REQUIRED_WP_VERSION')) define( 'WPCF7CF_REQUIRED_WP_VERSION', '4.1' );

js/scripts.js

Lines changed: 23 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/scripts.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/scripts_es6.js

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -230,14 +230,18 @@ var Wpcf7cfForm = function($form) {
230230
form.displayFields();
231231

232232
// bring form in initial state if the reset event is fired on it.
233+
// (CF7 triggers the 'reset' event by default on each successfully submitted form)
233234
form.$form.on('reset.wpcf7cf', form, function(e) {
234235
var form = e.data;
235236
setTimeout(function(){
236237
form.displayFields();
237238
form.resetRepeaters();
238239
if (form.multistep != null) {
239-
form.multistep.moveToStep(1);
240+
form.multistep.moveToStep(1, false);
240241
}
242+
setTimeout(function(){
243+
jQuery('.wpcf7-response-output', form.$form)[0].scrollIntoView({behavior: "smooth"});
244+
}, 400);
241245
},200);
242246
});
243247

@@ -350,7 +354,7 @@ Wpcf7cfForm.prototype.displayFields = function() {
350354
}
351355
});
352356

353-
$inputs.trigger('change');
357+
$inputs.each(function(){this.dispatchEvent(new Event("change",{"bubbles":true}))});
354358
}
355359

356360
if ($group.prop('tagName') === 'SPAN') {
@@ -417,7 +421,6 @@ Wpcf7cfForm.prototype.updateHiddenFields = function() {
417421
hidden_fields.push(jQuery(this).attr('name'));
418422
});
419423
if($group.attr('data-disable_on_hide') !== undefined) {
420-
console.log('disabling');
421424
$group.find(':input').prop('disabled', true);
422425
}
423426
} else {
@@ -889,18 +892,6 @@ function Wpcf7cfMultistep($multistep, form) {
889892
multistep.moveToStep(1);
890893
}
891894

892-
jQuery(document).ajaxComplete(function(e, xhr, settings){
893-
if (
894-
xhr.hasOwnProperty('responseJSON') &&
895-
xhr.responseJSON != null &&
896-
xhr.responseJSON.hasOwnProperty('status') &&
897-
xhr.responseJSON.hasOwnProperty('into') &&
898-
xhr.responseJSON.status === "mail_success"
899-
) {
900-
jQuery( xhr.responseJSON.into ).trigger('reset.wpcf7cf');
901-
}
902-
});
903-
904895
Wpcf7cfMultistep.prototype.validateStep = function(step_index) {
905896

906897
var multistep = this;
@@ -989,7 +980,7 @@ Wpcf7cfMultistep.prototype.validateStep = function(step_index) {
989980
});
990981

991982
};
992-
Wpcf7cfMultistep.prototype.moveToStep = function(step_index) {
983+
Wpcf7cfMultistep.prototype.moveToStep = function(step_index, scrollToTop = true) {
993984
var multistep = this;
994985
var previousStep = multistep.currentStep;
995986

@@ -1008,10 +999,12 @@ Wpcf7cfMultistep.prototype.moveToStep = function(step_index) {
1008999
.show()
10091000
.trigger('wpcf7cf_change_step', [previousStep, multistep.currentStep]);
10101001

1011-
const formEl = multistep.form.$form[0];
1012-
const topOffset = formEl.getBoundingClientRect().top;
1013-
if (topOffset < 0 && previousStep > 0) {
1014-
formEl.scrollIntoView({behavior: "smooth"});
1002+
if (scrollToTop) {
1003+
const formEl = multistep.form.$form[0];
1004+
const topOffset = formEl.getBoundingClientRect().top;
1005+
if (topOffset < 0 && previousStep > 0) {
1006+
formEl.scrollIntoView({behavior: "smooth"});
1007+
}
10151008
}
10161009

10171010
multistep.form.updateSummaryFields();

jsdoc-out/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ <h2><a href="index.html">Home</a></h2><h3>Namespaces</h3><ul><li><a href="wpcf7c
5656
<br class="clear">
5757

5858
<footer>
59-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.5</a> on Thu Jan 20 2022 13:05:25 GMT+0100 (Midden-Europese standaardtijd)
59+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.5</a> on Thu Jan 27 2022 21:16:07 GMT+0100 (Midden-Europese standaardtijd)
6060
</footer>
6161

6262
<script> prettyPrint(); </script>

jsdoc-out/scripts_es6.js.html

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,18 @@ <h1 class="page-title">Source: scripts_es6.js</h1>
258258
form.displayFields();
259259

260260
// bring form in initial state if the reset event is fired on it.
261+
// (CF7 triggers the 'reset' event by default on each successfully submitted form)
261262
form.$form.on('reset.wpcf7cf', form, function(e) {
262263
var form = e.data;
263264
setTimeout(function(){
264265
form.displayFields();
265266
form.resetRepeaters();
266267
if (form.multistep != null) {
267-
form.multistep.moveToStep(1);
268+
form.multistep.moveToStep(1, false);
268269
}
270+
setTimeout(function(){
271+
jQuery('.wpcf7-response-output', form.$form)[0].scrollIntoView({behavior: "smooth"});
272+
}, 400);
269273
},200);
270274
});
271275

@@ -378,7 +382,7 @@ <h1 class="page-title">Source: scripts_es6.js</h1>
378382
}
379383
});
380384

381-
$inputs.trigger('change');
385+
$inputs.each(function(){this.dispatchEvent(new Event("change",{"bubbles":true}))});
382386
}
383387

384388
if ($group.prop('tagName') === 'SPAN') {
@@ -445,7 +449,6 @@ <h1 class="page-title">Source: scripts_es6.js</h1>
445449
hidden_fields.push(jQuery(this).attr('name'));
446450
});
447451
if($group.attr('data-disable_on_hide') !== undefined) {
448-
console.log('disabling');
449452
$group.find(':input').prop('disabled', true);
450453
}
451454
} else {
@@ -917,18 +920,6 @@ <h1 class="page-title">Source: scripts_es6.js</h1>
917920
multistep.moveToStep(1);
918921
}
919922

920-
jQuery(document).ajaxComplete(function(e, xhr, settings){
921-
if (
922-
xhr.hasOwnProperty('responseJSON') &amp;&amp;
923-
xhr.responseJSON != null &amp;&amp;
924-
xhr.responseJSON.hasOwnProperty('status') &amp;&amp;
925-
xhr.responseJSON.hasOwnProperty('into') &amp;&amp;
926-
xhr.responseJSON.status === "mail_success"
927-
) {
928-
jQuery( xhr.responseJSON.into ).trigger('reset.wpcf7cf');
929-
}
930-
});
931-
932923
Wpcf7cfMultistep.prototype.validateStep = function(step_index) {
933924

934925
var multistep = this;
@@ -1017,7 +1008,7 @@ <h1 class="page-title">Source: scripts_es6.js</h1>
10171008
});
10181009

10191010
};
1020-
Wpcf7cfMultistep.prototype.moveToStep = function(step_index) {
1011+
Wpcf7cfMultistep.prototype.moveToStep = function(step_index, scrollToTop = true) {
10211012
var multistep = this;
10221013
var previousStep = multistep.currentStep;
10231014

@@ -1036,10 +1027,12 @@ <h1 class="page-title">Source: scripts_es6.js</h1>
10361027
.show()
10371028
.trigger('wpcf7cf_change_step', [previousStep, multistep.currentStep]);
10381029

1039-
const formEl = multistep.form.$form[0];
1040-
const topOffset = formEl.getBoundingClientRect().top;
1041-
if (topOffset &lt; 0 &amp;&amp; previousStep > 0) {
1042-
formEl.scrollIntoView({behavior: "smooth"});
1030+
if (scrollToTop) {
1031+
const formEl = multistep.form.$form[0];
1032+
const topOffset = formEl.getBoundingClientRect().top;
1033+
if (topOffset &lt; 0 &amp;&amp; previousStep > 0) {
1034+
formEl.scrollIntoView({behavior: "smooth"});
1035+
}
10431036
}
10441037

10451038
multistep.form.updateSummaryFields();
@@ -1571,7 +1564,7 @@ <h2><a href="index.html">Home</a></h2><h3>Namespaces</h3><ul><li><a href="wpcf7c
15711564
<br class="clear">
15721565

15731566
<footer>
1574-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.5</a> on Thu Jan 20 2022 13:05:25 GMT+0100 (Midden-Europese standaardtijd)
1567+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.5</a> on Thu Jan 27 2022 21:16:07 GMT+0100 (Midden-Europese standaardtijd)
15751568
</footer>
15761569

15771570
<script> prettyPrint(); </script>

jsdoc-out/wpcf7cf.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ <h2>wpcf7cf</h2>
7070

7171
<dt class="tag-source">Source:</dt>
7272
<dd class="tag-source"><ul class="dummy"><li>
73-
<a href="scripts_es6.js.html">scripts_es6.js</a>, <a href="scripts_es6.js.html#line1037">line 1037</a>
73+
<a href="scripts_es6.js.html">scripts_es6.js</a>, <a href="scripts_es6.js.html#line1030">line 1030</a>
7474
</li></ul></dd>
7575

7676

@@ -236,7 +236,7 @@ <h5>Parameters:</h5>
236236

237237
<dt class="tag-source">Source:</dt>
238238
<dd class="tag-source"><ul class="dummy"><li>
239-
<a href="scripts_es6.js.html">scripts_es6.js</a>, <a href="scripts_es6.js.html#line1488">line 1488</a>
239+
<a href="scripts_es6.js.html">scripts_es6.js</a>, <a href="scripts_es6.js.html#line1481">line 1481</a>
240240
</li></ul></dd>
241241

242242

@@ -399,7 +399,7 @@ <h5>Parameters:</h5>
399399

400400
<dt class="tag-source">Source:</dt>
401401
<dd class="tag-source"><ul class="dummy"><li>
402-
<a href="scripts_es6.js.html">scripts_es6.js</a>, <a href="scripts_es6.js.html#line1499">line 1499</a>
402+
<a href="scripts_es6.js.html">scripts_es6.js</a>, <a href="scripts_es6.js.html#line1492">line 1492</a>
403403
</li></ul></dd>
404404

405405

@@ -562,7 +562,7 @@ <h5>Parameters:</h5>
562562

563563
<dt class="tag-source">Source:</dt>
564564
<dd class="tag-source"><ul class="dummy"><li>
565-
<a href="scripts_es6.js.html">scripts_es6.js</a>, <a href="scripts_es6.js.html#line1420">line 1420</a>
565+
<a href="scripts_es6.js.html">scripts_es6.js</a>, <a href="scripts_es6.js.html#line1413">line 1413</a>
566566
</li></ul></dd>
567567

568568

@@ -748,7 +748,7 @@ <h5>Parameters:</h5>
748748

749749
<dt class="tag-source">Source:</dt>
750750
<dd class="tag-source"><ul class="dummy"><li>
751-
<a href="scripts_es6.js.html">scripts_es6.js</a>, <a href="scripts_es6.js.html#line1440">line 1440</a>
751+
<a href="scripts_es6.js.html">scripts_es6.js</a>, <a href="scripts_es6.js.html#line1433">line 1433</a>
752752
</li></ul></dd>
753753

754754

@@ -934,7 +934,7 @@ <h5>Parameters:</h5>
934934

935935
<dt class="tag-source">Source:</dt>
936936
<dd class="tag-source"><ul class="dummy"><li>
937-
<a href="scripts_es6.js.html">scripts_es6.js</a>, <a href="scripts_es6.js.html#line1464">line 1464</a>
937+
<a href="scripts_es6.js.html">scripts_es6.js</a>, <a href="scripts_es6.js.html#line1457">line 1457</a>
938938
</li></ul></dd>
939939

940940

@@ -1120,7 +1120,7 @@ <h5>Parameters:</h5>
11201120

11211121
<dt class="tag-source">Source:</dt>
11221122
<dd class="tag-source"><ul class="dummy"><li>
1123-
<a href="scripts_es6.js.html">scripts_es6.js</a>, <a href="scripts_es6.js.html#line1452">line 1452</a>
1123+
<a href="scripts_es6.js.html">scripts_es6.js</a>, <a href="scripts_es6.js.html#line1445">line 1445</a>
11241124
</li></ul></dd>
11251125

11261126

@@ -1307,7 +1307,7 @@ <h5>Parameters:</h5>
13071307

13081308
<dt class="tag-source">Source:</dt>
13091309
<dd class="tag-source"><ul class="dummy"><li>
1310-
<a href="scripts_es6.js.html">scripts_es6.js</a>, <a href="scripts_es6.js.html#line1477">line 1477</a>
1310+
<a href="scripts_es6.js.html">scripts_es6.js</a>, <a href="scripts_es6.js.html#line1470">line 1470</a>
13111311
</li></ul></dd>
13121312

13131313

@@ -1359,7 +1359,7 @@ <h2><a href="index.html">Home</a></h2><h3>Namespaces</h3><ul><li><a href="wpcf7c
13591359
<br class="clear">
13601360

13611361
<footer>
1362-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.5</a> on Thu Jan 20 2022 13:05:25 GMT+0100 (Midden-Europese standaardtijd)
1362+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.5</a> on Thu Jan 27 2022 21:16:07 GMT+0100 (Midden-Europese standaardtijd)
13631363
</footer>
13641364

13651365
<script> prettyPrint(); </script>

0 commit comments

Comments
 (0)