# Form\_for() and name

**URL:** <https://www.ruby-forum.com/t/form-for-and-name/72079>\
**Category:** Rails\
**Created:** [October 14, 2006, 1:48am UTC](https://www.ruby-forum.com/t/form-for-and-name/72079 "2006-10-14T01:48:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![adrianliem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ec9cab/32.png) [@adrianliem](https://www.ruby-forum.com/u/adrianliem)\
**Post date:** [October 14, 2006, 1:48am UTC](https://www.ruby-forum.com/t/form-for-and-name/72079/1 "2006-10-14T01:48:08Z")

</div>

how can i give name attributes for form\_for(), so it will give an output  
like . it is because that i need to access the form name  
for javascript manipulation.

as far as i know, name can only used in form\_tag(), but i currently have  
more than 50 forms that built using form\_for(). the structure is like  
this:

\<% form\_for symbol, item,  
:url =\> { :action =\> “do\_update”, :id =\> item } do |f| -%\>  
\<%= f.text\_field(:title)] %\>  
\<%= f.text\_field(:price)] %\>  
\<%= submit\_tag ‘Save’ -%\>  
\<% end -%\>

in case i have to change to form\_tag(), is there any structure  
suggestion to change my form\_for() to form\_tag() ?

thanks in advance, any inputs will help 🙂

---

<div class="post-metadata">

**Author:** ![adrianliem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ec9cab/32.png) [@adrianliem](https://www.ruby-forum.com/u/adrianliem)\
**Post date:** [October 14, 2006, 2:08am UTC](https://www.ruby-forum.com/t/form-for-and-name/72079/2 "2006-10-14T02:08:46Z")

</div>

On 10/13/06, Adrian L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> :url =\> { :action =\> “do\_update”, :id =\> item } do |f| -%\>  
> \<%= f.text\_field(:title)] %\>  
> \<%= f.text\_field(:price)] %\>  
> \<%= submit\_tag ‘Save’ -%\>  
> \<% end -%\>
> 
> in case i have to change to form\_tag(), is there any structure  
> suggestion to change my form\_for() to form\_tag() ?
> 
> thanks in advance, any inputs will help 🙂

[http://rails.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#M000387](http://rails.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#M000387)

Html attributes for the form tag can be given as :html =\> {?}. Example:

\<% form\_for :person, @person, :html =\> {:id =\> ‘person\_form’, :name  
=\> ‘foo’} do |f| %\>  
…  
\<% end %\>

–  
Rick O.  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)

---

<div class="post-metadata">

**Author:** ![adrianliem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ec9cab/32.png) [@adrianliem](https://www.ruby-forum.com/u/adrianliem)\
**Post date:** [October 14, 2006, 2:25am UTC](https://www.ruby-forum.com/t/form-for-and-name/72079/3 "2006-10-14T02:25:40Z")

</div>

thanks it works!  
i changed the :url into :html and it works  
i’ve read the API again and again but somehow i missed the html name  
attributes part.  
you don’t know how much it has help me…  
again, many thanks! 🙂

Rick O. wrote:

> Html attributes for the form tag can be given as :html =\> {ï¿½}. Example:
> 
> \<% form\_for :person, @person, :html =\> {:id =\> ‘person\_form’, :name  
> =\> ‘foo’} do |f| %\>  
> …  
> \<% end %\>
> 
> –  
> Rick O.  
> [http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
> [http://mephistoblog.com](http://mephistoblog.com)
