0

In order to prevent users from creating multiple submissions, I have implemented JavaScript to disable the submit button after it has been pressed.

My form page is processed by mailer.php, and then directed to a success page. Now, however, my form submits and is directed to mailer.php, and it appears the data is not submit.

I assume it has something to do with the onsubmit overriding the action=mailer.php.

Is this the cause and how can I fix it?

<form 
    onsubmit="document.getElementById('submit').disabled=true;document.getElementById('submit').value='Submitting, please wait...';"
    action="mailer.php" 
    method="post">
  <input 
      name="firstname" 
      type="text"
      placeholder="First Name" 
      class="form-content"/>
  </br>
  <input 
      name="surname" 
      type="text" 
      placeholder="Surname" 
      class="form-content"/>
  </br>

  [edit: removed irrelevant inputs]

  <div id="submitbutton">
    <input name="submit" type="submit" value="Submit" id="submit">
  </div>
</form>
freedomn-m
  • 27,664
  • 8
  • 35
  • 57
  • I'm confused, Your form action is set to mailer.php. Can't you just replace this with your success(.php?) page? – wizloc Sep 03 '15 at 14:17
  • The mailer collects the data and then emails it to me as well as pushes into a database. The mailer then redirects to the success page/ – Dave Mooney Sep 03 '15 at 14:19
  • 1
    Maybe the submit-button isn't sent through post after disabling - if you check at mailer.php --> if (isset($_POST['submit'])) ... wont work. – Chris Sep 03 '15 at 14:24
  • Any idea why it won't work? My mailer: "if(isset($_POST['submit'])) {" – Dave Mooney Sep 03 '15 at 14:27
  • http://stackoverflow.com/questions/7357256/disabled-form-inputs-do-not-appear-in-the-request – Layke Sep 04 '15 at 12:30

1 Answers1

0

Everything looks fine.

I've duplicated your form at:

http://jsfiddle.net/p9nc27qq/

Entering the values for the form:

enter image description here

The action is set up to send to http://requestb.in/1llii7k1

This site is a debugging of HTTP requests site...

If you inspect the page you can see it's receiving correctly:

http://requestb.in/1llii7k1?inspect

enter image description here

http://requestb.in/1llii7k1?inspect#1ipe11

Whatever you are doing is correct, so you are proabbaly misunderstanding the problem or not handling the request correctly on your server.. but the form is perfectly fine... as evidenced above.


Disabled values aren't submitted with the form also. So don't check for the presence of "submit"

Disabled form inputs do not appear in the request

Community
  • 1
  • 1
Layke
  • 51,422
  • 11
  • 85
  • 111