Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In rails controllers, how to prevent double submit (when user double-clic submit button or hit enter twice)?

Well, everything's in the title but I'll explain a little more :-)

My rails app contain many forms (Ajaxified or not).

To prevent users to submit twice or more some forms, I use Javascript.

There's my scenario for a Ajaxified form :

  • the user submit the form (clic or enter)
  • the javascript disable the submit button
  • the rails controller do things (like a Soap request or an insert in a DB)
  • the rails controller update the page and enable the submit button if necessary (in case of errors)

Now I want to add server side code to keeps things really clean if the user bypass the javascript.

Any suggestions?

like image 836
fro_oo Avatar asked Jul 01 '10 17:07

fro_oo


People also ask

How do you disable submit button after submit?

Enable / Disable submit button 1.1 To disable a submit button, you just need to add a disabled attribute to the submit button. $("#btnSubmit"). attr("disabled", true); 1.2 To enable a disabled button, set the disabled attribute to false, or remove the disabled attribute.

What exactly happens when the user clicks the submit button?

Most HTML forms have a submit button at the bottom of the form. Once all of the fields in the form have been filled in, the user clicks on the submit button to record the form data. The standard behaviour is to gather all of the data that were entered into the form and send it to another program to be processed.

How do I stop multiple submits Contact form 7?

php // Prevent Multi Submit on all WPCF7 forms add_action( 'wp_footer', 'prevent_cf7_multiple_emails' ); function prevent_cf7_multiple_emails() { ?> <script type="text/javascript"> var disableSubmit = false; jQuery('input. wpcf7-submit[type="submit"]'). click(function() { jQuery(':input[type="submit"]').


1 Answers

You can add the option :disable_with => "Please Wait..." to the submit tag.

like image 196
Jason Carpenter Avatar answered Oct 12 '22 02:10

Jason Carpenter