# Idiom for submit button?

**URL:** <https://www.ruby-forum.com/t/idiom-for-submit-button/49555>\
**Category:** Rails\
**Created:** [November 22, 2005, 8:35pm UTC](https://www.ruby-forum.com/t/idiom-for-submit-button/49555 "2005-11-22T20:35:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hgs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e5b9ba/32.png) [@hgs](https://www.ruby-forum.com/u/hgs)\
**Post date:** [November 22, 2005, 8:35pm UTC](https://www.ruby-forum.com/t/idiom-for-submit-button/49555/1 "2005-11-22T20:35:47Z")

</div>

What is the rails idiom for submit buttons on forms?  
All other field types have helpers, but button\_to creates its  
own form, so should not be used. I’ve looked in “Agile Web Dev. with  
Rails” but can’t see what I should do instead.

Is this “difficult” because it runs counter to AJAX type forms?

And, related, is there a way to ensure that hitting return in a  
field does not submit the form?

```
    Thank you,
    Hugh
```

---

<div class="post-metadata">

**Author:** ![hgs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e5b9ba/32.png) [@hgs](https://www.ruby-forum.com/u/hgs)\
**Post date:** [November 22, 2005, 8:39pm UTC](https://www.ruby-forum.com/t/idiom-for-submit-button/49555/2 "2005-11-22T20:39:48Z")

</div>

Hello Hugh !

2005/11/22, Hugh S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> What is the rails idiom for submit buttons on forms?  
> All other field types have helpers, but button\_to creates its  
> own form, so should not be used. I’ve looked in “Agile Web Dev. with  
> Rails” but can’t see what I should do instead.

What you’re looking for is “submit\_tag”: [http://rubyurl.com/ULX](http://rubyurl.com/ULX)  
[Peak Obsession](http://api.rubyonrails.com/classes/ActionView/Helpers/FormTagHelper.html#M000407)

> And, related, is there a way to ensure that hitting return in a  
> field does not submit the form?

Nope, this is a browser feature. The best you can do is attach a  
JavaScript event to your fields that prevents Enter from being a  
submit trigger. I wonder why you’d want to do that, though, as I find  
this a very important feature for me.

Hope that helps !

---

<div class="post-metadata">

**Author:** ![hgs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e5b9ba/32.png) [@hgs](https://www.ruby-forum.com/u/hgs)\
**Post date:** [November 22, 2005, 8:43pm UTC](https://www.ruby-forum.com/t/idiom-for-submit-button/49555/3 "2005-11-22T20:43:50Z")

</div>

On 11/22/05, Hugh S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> Thank you,
> Hugh
> 
> ```

\<%= submit\_tag ‘Go’ %\>  
[http://rails.rubyonrails.com/classes/ActionView/Helpers/FormTagHelper.html#M000407](http://rails.rubyonrails.com/classes/ActionView/Helpers/FormTagHelper.html#M000407)

As for hitting return to submit a form… i believe that’s more a  
function of your browser that does that.

–  
rick  
[http://techno-weenie.net](http://techno-weenie.net)
