# Stopping accidental form submissions

**URL:** <https://www.ruby-forum.com/t/stopping-accidental-form-submissions/189338>\
**Category:** Rails\
**Created:** [May 28, 2010, 11:27pm UTC](https://www.ruby-forum.com/t/stopping-accidental-form-submissions/189338 "2010-05-28T23:27:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![soheil\_danesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@soheil\_danesh](https://www.ruby-forum.com/u/soheil_danesh)\
**Post date:** [May 28, 2010, 11:27pm UTC](https://www.ruby-forum.com/t/stopping-accidental-form-submissions/189338/1 "2010-05-28T23:27:35Z")

</div>

Hi,

I’m using rails 3 and have an ajax form where users can add data,  
click submit, and it will be appended to a feed. The problem is if the  
users click submit (or press enter) multiple times, the form seems to  
be submitted multiple times as well resulting in the same item showing  
in the feed multiple times.

this is what my form tag looks like:  
\<% form\_for  
Discovery.new, :remote=\>true,  
:loading=\>“Form.Element.disable(‘commit’)”,  
:complete=\>“Form.Element.enable(‘commit’)”  
do |f| %\>

…

```
<%= f.submit 'Create', :id => "commit" %>

```

as you can see i’ve tried to disable the submit button. however the  
javascript code does not get generated.

Would very much appreciate some help with this.

Cheers,  
Soheil

---

<div class="post-metadata">

**Author:** ![soheil\_danesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@soheil\_danesh](https://www.ruby-forum.com/u/soheil_danesh)\
**Post date:** [May 29, 2010, 9:13am UTC](https://www.ruby-forum.com/t/stopping-accidental-form-submissions/189338/2 "2010-05-29T09:13:22Z")

</div>

On 28 May 2010 20:45, soheil danesh [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Discovery.new, :remote=\>true, :loading=\>“Form.Element.disable(‘commit’)”, :complete=\>“Form.Element.enable(‘commit’)”  
> do |f| %\>
> 
> …
> 
> \<%= f.submit ‘Create’, :id =\> “commit” %\>
> 
> as you can see i’ve tried to disable the submit button. however the  
> javascript code does not get generated.

I don’t see anything there that will disable the button after it is  
clicked. Have a look at the disable\_with option on f.submit.

Colin
