hello, as with the default wordpress editor, it would be great if Gravity Forms were able to prompt (warning popup confirm/cancel) you when you if click close the browser or tab without submitting the form.
This is especially essential for those who use frontend post submission forms.
Some users have already told me that they were writing a text longer than 500-800 words and lost everything by accidentally closing the tab or crashing the system/browser
P.S: the save and resume function does not solve the problem.
I added an HTML field to a form and added this script to it:
<script>
jQuery(document).on('mouseleave', leaveFromTop);
function leaveFromTop(e){
if( e.clientY < 0 )
alert('Please be sure you submit the form before you go!');
}
</script>
You can test that out on the form on my site here:
[SITE REMOVED]
Thank you Chris. But this function only gives a simple warning. If the user accidentally clicks in close, this javascript does not prevent it. I would like it to be the same as in Wordpress post edit screen, which issues the warning with button ask to confirm whether you really want to close the tab or the browser.
basically is to prevent window closing unless the user clicks āconfirmā
You can of course extend that example to catch all sorts of manner of closing. That was just a quick proof of concept. You would copy what WordPress is doing, or add other conditions.
Hello Chris, but Iām not a developer. I even tried using this code snippet https://jsfiddle.net/sogata/Lx82optd/ but it does not work for gravity forms.
Try this. It checks if the user has clicked on any of the inputs, if they have then itāll fire the warning when they go to close the tab. If the user doesnāt click on any of the inputs itāll let them leave without bothering them. I just did a rough test on this, it may not be perfect.
@lonepc Yeah, it wasnāt meant for multi page use. and I did mention I wrote when I was leaving for the day and didnāt do any testing on it. My apologies.
@nickhempsey, Where do I enable AJAX? My form is conditional logic / calculation heavy - Would AJAX affect the formās speed in either direction?
I am nervous about using AJAX because I use a bunch of add-ons and Iām not sure whether using AJAX may introduce some compatibility issues. Ideally I would appreciate a modified version of the snippet you wrote.
@lonepc You enable ajax in the shortcode [gravityforms id="##" ajax=ātrueā]
AJAX shouldnāt affect any of the addons, conditional logic, or calculations. AJAX just allows the form to be submitted without the need for a page refresh. You can also just do some testing on a separate page before moving to production.
While I understand youād appreciate a modified version of that snippet itās actually a complicated problem, Iām a bit hung up on it, and frankly Iām just another GForm user trying to help out. Not trying to be rude but Iām not being paid to do any of this work and I have a full time job and 4 children. lol
The Problem
Essentially you have to somehow change the $userStartedForm variable to false when the user clicks the submit button but before the form starts to refresh the page. This is where Iām struggling a bit, because in all of my testing what happens is this:
Start using form.
$userStartedForm is set to true.
Click Submit or Next Page
Page Refreshes
$userStartedForm is set to false.
I need to figure out a way to interrupt the page refresh and change the $userStartedForm variable. Unless someone else has an idea of how to do this Iām a bit stuckā¦ and therefore youāre stuck as well.