# How do you manually specify the name of a submit button?

**URL:** <https://www.ruby-forum.com/t/how-do-you-manually-specify-the-name-of-a-submit-button/185267>\
**Category:** Rails\
**Created:** [March 17, 2010, 4:45am UTC](https://www.ruby-forum.com/t/how-do-you-manually-specify-the-name-of-a-submit-button/185267 "2010-03-17T04:45:36Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ct9a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ad7895/32.png) [@ct9a](https://www.ruby-forum.com/u/ct9a)\
**Post date:** [March 17, 2010, 4:45am UTC](https://www.ruby-forum.com/t/how-do-you-manually-specify-the-name-of-a-submit-button/185267/1 "2010-03-17T04:45:36Z")

</div>

hi, guys,

I have an app which has two forms on the page.

Both forms are based on a “search” model.

1. Search by keyword only (hence, only 1 element being “keyword”)
2. Search by a few different attributes (including keyword).  
Attributes are such as price, brand and make.

## When constructing a search form, “form\_for” will be used. Here’s an extract from one of them: -------------------- Extract start

\<% form\_for :search, :url =\> search\_path, :html =\> {:method =\> “get”}  
do |f| %\>

 \<%= render :partial =\> 'search/categories' %\> 

\<%= f.label :title\_like, "Brand" %\> \<%= f.text\_field :brand\_like %\>

…

\<%= f.label :title\_like, "Keyword" %\> \<%= f.text\_field :title\_like %\>

\<%= f.submit 'Search' %\>

\<% end %\> -------------------- Extract end -------------------------------------------------------------------------------------

Now, when the page loads, there are two search forms and both of them  
will have submit buttons with identical names being “search\_submit”.

This will obviously cause a failure in the w3c html validator due to  
the identical elements appearing more than once in a page.

1. Is there any way we can specify the name of a given submit button?
2. Is there an alternative such that I can still maintain two search  
forms in the same page?

thank you.

---

<div class="post-metadata">

**Author:** ![ct9a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ad7895/32.png) [@ct9a](https://www.ruby-forum.com/u/ct9a)\
**Post date:** [March 17, 2010, 4:52am UTC](https://www.ruby-forum.com/t/how-do-you-manually-specify-the-name-of-a-submit-button/185267/2 "2010-03-17T04:52:37Z")

</div>

On Tue, 2010-03-16 at 20:44 -0700, ct9a wrote:

> extract from one of them:
> 
> -------------------- Extract end 2) Is there an alternative such that I can still maintain two search forms in the same page?

* * *

f.submit ‘Search Categories’

f.submit ‘Search Something Else’

Craig

–  
This message has been scanned for viruses and  
dangerous content by MailScanner, and is  
believed to be clean.

---

<div class="post-metadata">

**Author:** ![ct9a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ad7895/32.png) [@ct9a](https://www.ruby-forum.com/u/ct9a)\
**Post date:** [March 17, 2010, 4:56am UTC](https://www.ruby-forum.com/t/how-do-you-manually-specify-the-name-of-a-submit-button/185267/3 "2010-03-17T04:56:43Z")

</div>

Thanks craig but my mistake, guys.

I meant the “id” attribute.

Hence, we’ll get two submit buttons:

(first form)

(second form)

---

<div class="post-metadata">

**Author:** ![ct9a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ad7895/32.png) [@ct9a](https://www.ruby-forum.com/u/ct9a)\
**Post date:** [March 17, 2010, 5:14am UTC](https://www.ruby-forum.com/t/how-do-you-manually-specify-the-name-of-a-submit-button/185267/4 "2010-03-17T05:14:23Z")

</div>

Gordon Y. wrote:

> Thanks craig but my mistake, guys.
> 
> I meant the “id” attribute.
> 
> Hence, we’ll get two submit buttons:
> 
> (first form)
> 
> (second form)

Dear friend,

```
       Why can't use "submit_tag" in both partial and in the current 

```

form ? While using it , it won’t have this id attribute.

---

<div class="post-metadata">

**Author:** ![ct9a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ad7895/32.png) [@ct9a](https://www.ruby-forum.com/u/ct9a)\
**Post date:** [March 17, 2010, 5:17am UTC](https://www.ruby-forum.com/t/how-do-you-manually-specify-the-name-of-a-submit-button/185267/5 "2010-03-17T05:17:12Z")

</div>

Smart idea! thank you. I will try it out and revert.  
Cheers!

---

<div class="post-metadata">

**Author:** ![ct9a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ad7895/32.png) [@ct9a](https://www.ruby-forum.com/u/ct9a)\
**Post date:** [March 17, 2010, 5:07am UTC](https://www.ruby-forum.com/t/how-do-you-manually-specify-the-name-of-a-submit-button/185267/6 "2010-03-17T05:07:50Z")

</div>

On Wed, 2010-03-17 at 14:54 +1100, Gordon Y. wrote:

> ```
> > I have an app which has two forms on the page.
> > -------------------- Extract start
> > <%= f.text_field :brand_like %>
> > <% end %>
> > This will obviously cause a failure in the w3c html
> ----
> f.submit 'Search Categories'
>     
> f.submit 'Search Something Else'
> 
> ```

* * *

untested but I think should work but I got the impression that the ‘id’  
if not specified would dynamically pick from the action and the name.

\<% form\_for :search, :url =\> search\_path, :html =\> {:method =\>  
“get”, :id =\> “something”} do |f| %\>

Craig

–  
This message has been scanned for viruses and  
dangerous content by MailScanner, and is  
believed to be clean.

---

<div class="post-metadata">

**Author:** ![ct9a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ad7895/32.png) [@ct9a](https://www.ruby-forum.com/u/ct9a)\
**Post date:** [March 17, 2010, 10:13am UTC](https://www.ruby-forum.com/t/how-do-you-manually-specify-the-name-of-a-submit-button/185267/7 "2010-03-17T10:13:55Z")

</div>

On 17 March 2010 03:54, Gordon Y. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> (second form)

I can confirm that  
\<%= f.submit “Search”, :id =\> “a\_search” %\>  
\<%= f.submit “Search”, :id =\> “another\_search” %\>  
will give different id’s and so keep the html valid

Colin

---

<div class="post-metadata">

**Author:** ![ct9a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ad7895/32.png) [@ct9a](https://www.ruby-forum.com/u/ct9a)\
**Post date:** [March 17, 2010, 5:42am UTC](https://www.ruby-forum.com/t/how-do-you-manually-specify-the-name-of-a-submit-button/185267/8 "2010-03-17T05:42:22Z")

</div>

Problem solved. Thanks, Loganathan .  
W3C html validator is happy with the output generated.

---

<div class="post-metadata">

**Author:** ![ct9a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ad7895/32.png) [@ct9a](https://www.ruby-forum.com/u/ct9a)\
**Post date:** [March 17, 2010, 11:28am UTC](https://www.ruby-forum.com/t/how-do-you-manually-specify-the-name-of-a-submit-button/185267/9 "2010-03-17T11:28:16Z")

</div>

bravo.  
another brilliant reply
