views:

40

answers:

1

I am trying to get a form like this: alt text

Name form:

<% form_tag  do %>
      <p>
        <label for="name">Name:</label>
        <%= text_field_tag :search%>  <%= submit_tag "Go"%>
      </p>              
<% end %>

Phone Number

<% form_tag  do %>
      <p>
        <label for="ph">Phone Number:</label>
        <%= text_field_tag :phone%> <%= submit_tag "Go"%>
      </p>              
<% end %> 

What should I do with Seta and Setb values? Do I need to combine them with form tags? if so, then which ?

Functionality of the form will be that user selects either Seta or Setb and enter something in Name or Phone number and click corresponding Go button.

+2  A: 

There isn't a way to submit data for a form which is outside of a form. But, I can think of two solutions:

Have the whole thing in one big form and figure out what the user wanted to do in the handler code. This would be pretty simple (just find a blank box) to do.

Alternatively, you could have clicking "seta" or "setb" invoke a Javascript function which edits a hidden field in both forms. This might be closer to what you actually want, although it is a little more error prone (especially if people have Javascript turned off or their browser doesn't support it).

Travis Gockel
I agree, and use something like the first option in production. The only other way I can think of to submit data not in a form is in the query string for the URL you post to. Not a good idea though - Travis's answers are solid techniques.
Andrew Kuklewicz