
-
AuthorPosts
-
October 20, 2017 at 7:13 am #866606
Hi I have created a form with a check box area and an email address in it. By default the check box area is ticked and I have selected Is Not Empty element validation for the check box.
When the page loads the check box is ticked by default and for example if I untick the checkbox and type in a valid email address its still submitting the form.
What I want to do is to stop the form from sending if the checkbox is unticked.
I was just wondering if you could help me out.
Kind regards
October 21, 2017 at 12:12 pm #867012Hey mattlang,
Could you please give us a link to your website, we need more context to be able to help you.
Best regards,
VictoriaOctober 21, 2017 at 12:44 pm #867031This reply has been marked as private.October 23, 2017 at 6:47 am #867460Hi,
We can disable the submit button when the checkbox is unticked. Please add this script in the functions.php file.
// custom script function add_custom_script(){ ?> <script type="text/javascript"> (function($){ $(document).ready(function() { $("#top input[type='checkbox']").on('change', function(e) { disableSubmit(this); }); function disableSubmit(element) { var submit = $('#top input[type="submit"]'); if ($(element).is(':checked')) { submit.removeAttr('disabled'); } else { submit.attr('disabled', 'disabled'); } } }); })(jQuery); </script> <?php } add_action('wp_footer', 'add_custom_script');
Best regards,
IsmaelOctober 23, 2017 at 7:20 am #867473This reply has been marked as private.October 24, 2017 at 5:41 am #867964Hi,
Glad that it is working. Please replace the script with the following code.
// custom script function add_custom_script(){ ?> <script type="text/javascript"> (function($){ $(document).ready(function() { function disableSubmit(element) { var submit = $('#top input[type="submit"]'); if ($(element).is(':checked')) { submit.removeAttr('disabled'); } else { submit.attr('disabled', 'disabled'); } } $("#top input[type='checkbox']").on('change', function(e) { disableSubmit(this); }); function addErrorNotif(element) { var form, error; form = $(element).parents('form'); error = $(form).find('.error .is_email'); $('<span class="error_notif">Please enter a valid email address!</span>').insertAfter(error); setTimeout(function() { $('.error_notif').remove(); }, 3000); } $('#top input[type="submit"]').on('click', function() { setTimeout( $.proxy(function() { addErrorNotif(this); }, this), 1000); }); }); })(jQuery); </script> <?php } add_action('wp_footer', 'add_custom_script');
You can change the style of the error container by using the “error_notif” class selector.
Best regards,
IsmaelOctober 24, 2017 at 5:50 am #867971This reply has been marked as private.October 24, 2017 at 6:02 pm #868316Hi,
Glad that Ismael helped you. Thanks for using Enfold :)
Best regards,
Nikko -
AuthorPosts
- The topic ‘Check box is submitting form even when the not empty validation is enabled.’ is closed to new replies.