# Hidden fields in forms

**URL:** <https://www.ruby-forum.com/t/hidden-fields-in-forms/97579>\
**Category:** Rails\
**Created:** [July 8, 2006, 3:27am UTC](https://www.ruby-forum.com/t/hidden-fields-in-forms/97579 "2006-07-08T03:27:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ptremblett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/dc4da7/32.png) [@ptremblett](https://www.ruby-forum.com/u/ptremblett)\
**Post date:** [July 8, 2006, 3:27am UTC](https://www.ruby-forum.com/t/hidden-fields-in-forms/97579/1 "2006-07-08T03:27:04Z")

</div>

Please can someone show me the correct syntax for a hidden field in  
forms, this is my code

\<%= start\_form\_tag :action =\> ‘create’ %\>

\<% hidden\_field ‘line\_item’, ‘client\_id’, :value =\> session[:client\_id]  
%\>  
\<% hidden\_field ‘line\_item’, ‘product\_id’, :value =\> 999999 %\>  
\<% hidden\_field ‘line\_item’, ‘sort\_key’, :value =\> “saa” %\>  
\<% hidden\_field ‘line\_item’, ‘category’, :value =\> “adi” %\>  
\<% hidden\_field ‘line\_item’, ‘model’, :value =\> “additional item” %\>  
\<% hidden\_field ‘line\_item’, ‘prod\_num’, :value =\> “999” %\>  
\<% hidden\_field ‘line\_item’, ‘image\_s’, :value =\>  
“/images/til/aditem.jpg” %\>

| Quantity : | \<%= text\_field 'line\_item', 'quantity' %\> |
| Description : | \<%= text\_area 'line\_item', 'description', :cols=\>"99", :rows=\>"2" %\> |
| Price : | \<%= text\_field 'line\_item', 'unit\_price' %\> |
| |

\<%= submit\_tag ‘Create Additional Item’ %\>  
\<%= end\_form\_tag %\>

Rails never complains but the record never appears.  
If I take the “hidden\_field” lines out, a record is created.

Thanks,  
Paul Thompson

---

<div class="post-metadata">

**Author:** ![ptremblett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/dc4da7/32.png) [@ptremblett](https://www.ruby-forum.com/u/ptremblett)\
**Post date:** [July 8, 2006, 3:43am UTC](https://www.ruby-forum.com/t/hidden-fields-in-forms/97579/2 "2006-07-08T03:43:07Z")

</div>

On Sat, 2006-07-08 at 13:25 +1200, Paul Jonathan T. wrote:

> \<% hidden\_field ‘line\_item’, ‘product\_id’, :value =\> 999999 %\>
> 
> Price Rails never complains but the record never appears. If I take the "hidden\_field" lines out, a record is created.
> * * *
> 
> I tend to use an “=”
> 
> \<%= hidden\_field …
> 
> you probably want to enclose the html in brackets…
> 
> \<%= hidden\_field ‘controller’, ‘column’, {:value =\> ‘some value’} %\>  
> but I’m not certain that’s necessary
> 
> Craig

---

<div class="post-metadata">

**Author:** ![ptremblett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/dc4da7/32.png) [@ptremblett](https://www.ruby-forum.com/u/ptremblett)\
**Post date:** [July 8, 2006, 3:43am UTC](https://www.ruby-forum.com/t/hidden-fields-in-forms/97579/3 "2006-07-08T03:43:15Z")

</div>

you’re missing the ‘=’

\<%= hidden\_field ‘line\_item’, ‘client\_id’ %\>

---

<div class="post-metadata">

**Author:** ![ptremblett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/dc4da7/32.png) [@ptremblett](https://www.ruby-forum.com/u/ptremblett)\
**Post date:** [July 8, 2006, 3:46am UTC](https://www.ruby-forum.com/t/hidden-fields-in-forms/97579/4 "2006-07-08T03:46:25Z")

</div>

On Fri, 2006-07-07 at 18:41 -0700, Craig W. wrote:

> > \<% hidden\_field ‘line\_item’, ‘client\_id’, :value =\> session[:client\_id] %\>  
> > :cols=\>“99”, :rows=\>“2” %\>
> 
> but I’m not certain that’s necessary

* * *

that doesn’t seem right… {value=‘some value’} seems better

Craig

---

<div class="post-metadata">

**Author:** ![ptremblett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/dc4da7/32.png) [@ptremblett](https://www.ruby-forum.com/u/ptremblett)\
**Post date:** [July 8, 2006, 4:32am UTC](https://www.ruby-forum.com/t/hidden-fields-in-forms/97579/5 "2006-07-08T04:32:52Z")

</div>

Thanks for the help.

This worked:

\<%= hidden\_field ‘line\_item’, ‘product\_id’, :value =\> ‘999999’ %\>

Craig, it did not need the curly brackets.

Thanks to all,

Paul
