0

I have simple email script with few forms and I am getting duplicate submissions...

So, what is the easiest way to prevent duplicate submissions?

My code..

<form action="main_contact.php" method="post" name="contact_form">
                  <input type="text" name="contact_name" placeholder="Name">
                  <input type="email" name="contact_email" placeholder="Email">
                  <input type="text" name="contact_subject" placeholder="Subject">
                  <textarea cols="30" name="contact_message" rows="10" placeholder="Your Message"></textarea>
                   <input type="submit" value="Send">  
                </form>

<?php
                  if(isset($_POST['contact_form'])){ 
                    var_dump($_POST);
                  }
                ?>

3 Answers3

1

You can use jQuery to disable submit button after the form has been submitted:

$('form[name="contact_form"]').submit(function(){
    $(this).find('input[type="submit"]').prop('disabled', true);
});
  • This is a straight forward approach to it. Furthermore, make sure that you are displaying a success message to the user following a submission. Even redirecting to a success page is effective, and can help track conversion. :) – Brian Schroeter Sep 18 '16 at 22:18
0

you just need to disable or make visibility hidden after just click on submit button. fist give a id to the submit button

<input type="submit" value="Send" id="sub_id"> 

and then make it hidden or disable in javascript once you submit the form

document.getElementById('sub_id').style.visibility='hidden'; 
Manoj Gupta
  • 63
  • 1
  • 1
  • 9
-1

If you used any framework like Laravel5 or Symfony you would get it "out of the box".

In short: Register a session token and invalidate it after first form submission.

jakub wrona
  • 2,212
  • 17
  • 17