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

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| %>
<div id="category_div">
    <%= render :partial => 'search/categories' %>
  </div>
  <p>
  <%= f.label :title_like, "Brand" %>
  <%= f.text_field :brand_like %>
  </p>

   ...
  <p>
  <%= f.label :title_like, "Keyword" %>
  <%= f.text_field :title_like %>
  </p>
  <p>
  <%= f.submit 'Search' %>
  </p>
<% 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?

Thanks craig but my mistake, guys.

I meant the “id” attribute.

Hence, we’ll get two submit buttons:

<input id="search_submit" name="commit" type="submit" value="Search" /> (first form)

  <input id="search_submit" name="commit" type="submit" value="Search" /> (second form)

Thanks craig but my mistake, guys.

I meant the "id" attribute.

Hence, we'll get two submit buttons:

<input id="search_submit" name="commit" type="submit" value="Search" /> (first form)

  <input id="search_submit" name="commit" type="submit" value="Search" /> (second form)

        > 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| %>
        > <div id="category_div">
        > <%= render :partial => 'search/categories' %>
        > </div>
        > <p>
        > <%= f.label :title_like, "Brand" %>
        > <%= f.text_field :brand_like %>
        > </p>
        >
        > ...
        > <p>
        > <%= f.label :title_like, "Keyword" %>
        > <%= f.text_field :title_like %>
        > </p>
        > <p>
        > <%= f.submit 'Search' %>
        > </p>
        > <% 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?
        >
        
        ----
        f.submit 'Search Categories'
        
        f.submit 'Search Something Else'

Gordon Yeong wrote:

Thanks craig but my mistake, guys.

I meant the "id" attribute.

Hence, we'll get two submit buttons:

  <input id="search_submit" name="commit" type="submit" value="Search"
/> (first form)

  <input id="search_submit" name="commit" type="submit" value="Search"
/> (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!

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

Thanks craig but my mistake, guys.

I meant the "id" attribute.

Hence, we'll get two submit buttons:

  <input id="search_submit" name="commit" type="submit" value="Search" />
(first form)

  <input id="search_submit" name="commit" type="submit" value="Search" />
(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

bravo.
another brilliant reply