title: Avoid Race Conditions in PHP on Submit: Please do not click submit more than once!
body: <p>A while back, online apps used to say, "do not click submit more than once." That's gone now, right? How do you guard against that in, say, PHP?</p>
  
  <p>One solution I'm using involves putting a variable in the Session, so you cannot submit to a page more than once every 10 seconds. That way the database work will have completed so the normal checks can take place. Obviously, this feels like a hack and probably is.</p>
  
  <p><strong>Edit:</strong> Thanks everybody for the Javascript solution. That's fine, but it is a bit of work. 1) It's an input type=image and 2) The submit has to keep firing until the <a href="http://labs.adobe.com/technologies/spry/" rel="nofollow noreferrer">Spry stuff</a> says it's okay. This edit is just me complaining, basically, since I imagine that after looking at the Spry stuff I'll be able to figure it out.</p>
  
  <p><strong>Edit:</strong> Not that anyone will be integrating with the Spry stuff, but here's my final code using Prototype for the document.getElementByid. Comments welcome!</p>
  
  <pre><code>function onSubmitClick() {
      var allValid = true;
      var queue = Spry.Widget.Form.onSubmitWidgetQueue; 
      for (var i=0;i&lt;queue.length; i++) {
          if (!queue[i].validate()) {
              allValid = false;
              break;
          }
      }
  
      if (allValid) {
          $("theSubmitButton").disabled = true;
          $("form").submit();
      }
  }
  </code></pre>
  
  <p>For some reason, the second form submit was necessary...</p>