Get form id

user splash wrote:

Hi,

Can anyone tell me how do I get form id and print it out puts ?

Thanks

Step 1: Rephrase your question and be more specific.
Step 2: Receive Help.
Step 3: Rejoice.

Although this may seem a bit harsh to start with, I think Phil Tayo is right. user splash, please be more elaborate with your questions. The more detail you give us, the more likely we are to help you.

hmmm still not 100% sure what you mean....does this example help?

If you had a file called register.rhtml and a model called user....

<% form_for :user do |form| %>

<div class = "form_row">
   <label for="screen_name">Screen name:</label>
  <%=form.text_field :screen_name%>
</div>

<div class = "form_row">
  <%=submit_tag "Register!", :class => "submit" %>
</div>

<% end %>

In the controller in the "register" method (I think ruby takes the
controller method name from the name of the .rhtml file) you can then
receive the form using "params[:user]" and then do @user =
User.new(params[:user]) to create a new user....

Does this help? Or am I off track?

Phil Tayo wrote:

hmmm still not 100% sure what you mean....does this example help?

If you had a file called register.rhtml and a model called user....

<% form_for :user do |form| %>

<div class = "form_row">
   <label for="screen_name">Screen name:</label>
  <%=form.text_field :screen_name%>
</div>

<div class = "form_row">
  <%=submit_tag "Register!", :class => "submit" %>
</div>

<% end %>

In the controller in the "register" method (I think ruby takes the
controller method name from the name of the .rhtml file) you can then
receive the form using "params[:user]" and then do @user =
User.new(params[:user]) to create a new user....

Does this help? Or am I off track?

Hmm....Sorry if my question is not clear. What I was trying to do is to
get the form's id, and try to submit it using a link outside the form.

Example:

<% form_for :user, :url => { :action => :save_user}, :html => { :id =>
"id_of_form" } do |form| %>

<div class = "form_row">
   <label for="screen_name">Screen name:</label>
  <%=form.text_field :screen_name%>
</div>
<%= end %>

  <%=link_to_function "Save", "myform.submit();" %>

I want to ask is there anyway to get id_of_form which is the form's id ?
Correct me if any part of my code is wrong. Is it possible to submit
form with the submit link outside of the form?

Thanks

<%= end %>

  <%=link_to_function "Save", "myform.submit();" %>

I want to ask is there anyway to get id_of_form which is the form's id ?
Correct me if any part of my code is wrong. Is it possible to submit
form with the submit link outside of the form?

Thanks

hmm how about:

<%=link_to "Save", {:action => "save", :form_id => "user"} %>

does that work?

the answer may well be yes buy you can just put an extra hidden input
tag in the form like:
<input type="hidden name="formid" value="1">
and access it via params[:formid]

Adam

Adam Jones wrote:

the answer may well be yes buy you can just put an extra hidden input
tag in the form like:
<input type="hidden name="formid" value="1">
and access it via params[:formid]

Adam

Hi,

Just to make sure, where should I put this hidden field ? I tried
placing it in my side bar but can't get value

Thanks

sorry also forgot to close the tag...
its:

<input type="hidden" name="formid" value="1"/>

.....put this hidden field anywhere between <form > and </form> for
the form you want to reference