how to submit a form and send fields that are not in the form tag
I am trying to get a form like this:
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 开发者_StackOverflowI 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.
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).
精彩评论