Exit Confirmation Popup
-
Hi,
I want to create an exit confirmation popup for a specific form page.
I have found this topic: https://www.greengeeks.com/tutorials/article/incomplete-form-confirmation-in-wordpress/
I followed the guide to create a custom plugin and it kind of works.
Here’s what I did:
1. Created a folder on my computer, called
confirm-leaving-form
.2. Added a PHP file, called
confirm-leaving.php
, inside the folder:<?php /** * Confirm Leaving * Plugin Name: Confirm Leaving Form * Plugin URI: https://www.mydomainexample.com * Description: This plugin shows a warning to users when try they forget to hit submit button on a comment form. * Version: 1.0.0 * Author: My name * Author URI: https://www.mydomainexample.com * License: GPL-2.0+ * License URI: https://www.gnu.org/licenses/gpl-2.0.txt */ function wpb_confirm_leaving_js() { wp_enqueue_script( 'Confirm Leaving Form', plugins_url( 'js/confirm-leaving.js', __FILE__ ), array('jquery'), '1.0.0', true ); } add_action('wp_enqueue_scripts', 'wpb_confirm_leaving_js');
3. Created another folder, called
js
, inside theconfirm-leaving-form
folder.4. Added a JavaScript file, called
confirm-leaving.js
, inside the newjs
folder:jQuery(document).ready(function($) { $(document).ready(function() { needToConfirm = false; window.onbeforeunload = askConfirm; }); function askConfirm() { if (needToConfirm) { // Put your custom message here return "Leaving so soon? Your data will be lost if you continue."; } } $("#forminator-module-2959").change(function() { needToConfirm = true; }); })
#forminator-module-2959
is the ID of my form.5. Uploaded the whole
confirm-leaving-form
folder to the “/plugins/” directory of my website (used the FileZilla FTP application).6. Activated the new plugin on WordPress.
Here are the issues:
1. The popup only appears if the user has started filling out the form.
2. The popup does not appear if the user has not answered any radio, checkbox, select etc. questions. Text input questions do not trigger the popup.
3. The popup appears when the user has filled out the form and hits the “Submit” button.Ideally, I would like the exit confirmation popup to appear even if the from is empty but not appear when the user completes the form and tries to submit it.
Is this possible?
I would highly appreciate any help I can get.
Thanks
- The topic ‘Exit Confirmation Popup’ is closed to new replies.