[Résolu] prevent user from clicking twice on the submiy button
This support ticket is created Il y a 8 années et 3 mois. There's a good chance that you are reading advice that it now obsolete.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
I have a CRED form which works fine, but if the user click twice or 3 times on the submit button, the post is created 2 or 3 times.
I tried:
add_filter('cred_form_validate', 'prevent_multiple_send_func',10,2);
function prevent_multiple_send_func($field_data, $form_data)
{
list($fields,$errors) = $field_data;
// validate if specific form
if ($form_data['id']==56)
{
$v = "something from somewhere";
if(!isset($_COOKIE["CRED_56"])){
setcookie("CRED_56", "something from somewhere", time()+15); /* expire in 15 seconds */
}
else{
$errors['post_title'] = 'Please do not multiple send';
}
}
return array($fields,$errors);
}
But no success. Any clue please? or any javascript to prevent the user from clicking more than once?
Regards
Nabil
Thanks Waqas but the suggested JS does not work, after ading the js code and when I press the submit button, the form is not even submitted (no post is created)
Can you please provide a link or access to the page where form is located? So I can take a look and find a solution. Since the same solution I applied on my local host and is working fine.
I have enabled your next reply as private, please input all details in that area. Please mention the links to the pages, views, forms, CPTs and configurations in question.
Please take a backup of your site, before proceeding.
Please notice that the submit button is being hide when form is submitted. Because if we apply a readonly or disabled property, the form isn't submitted, probably form submission is also looking for that.
Anyhow, secondly, notice the .valid() method. Because form is using validation, so we can check if the whole form was validated successfully. In this case, form is submitted and we want to hide the submit button to prevent accidental submissions - otherwise, the button will be shown (if form has validation issues).
I hope this will fix your problem. As an idea, you can use a span or div to show when the button is hide, saying something like "Processing, please wait..." - just a thought 🙂