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

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.

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.

Thanks craig but my mistake, guys.

I meant the “id” attribute.

Hence, we’ll get two submit buttons:

(first form)

(second form)

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.

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

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.

On 17 March 2010 03:54, Gordon Y. [email protected] 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

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

bravo.
another brilliant reply