# Hidden fields

**URL:** <https://www.ruby-forum.com/t/hidden-fields/175508>\
**Category:** Rails\
**Created:** [September 14, 2009, 11:30pm UTC](https://www.ruby-forum.com/t/hidden-fields/175508 "2009-09-14T23:30:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [September 14, 2009, 11:30pm UTC](https://www.ruby-forum.com/t/hidden-fields/175508/1 "2009-09-14T23:30:12Z")

</div>

Similar (but different) to another thread called ‘accessing post array’,  
I have some records that I need sent via an array but I don’t want to  
use a text field but rather a hidden field because I don’t want them  
tampered with.

Simplifying my form quite a bit…

\<% form\_for :supptrans, @supptrans, :url =\> { :action =\>  
“print\_checks” } do |form| %\>

... ... \<%= form.hidden\_field :paid\_invoices, {:value =\> check\_due.id} %\> \<%= text\_field 'check\_number', 'check\_number', :size =\> '8' %\> \<%= submit\_tag 'Print Checks' %\> \<% end %\>

where I need the form to submit the starting check number but I also  
need the check\_due.id in an array so I know which checks are going to be  
printed.

this  
\<%= form.hidden\_field :paid\_invoices, {:value =\> check\_due.id} %\>  
is only the latest attempt but I have tried many things including…  
\<%= hidden\_field :paid\_invoices, “paid\_invoices[]”, {:value =\>  
check\_due.id} %\>

but none of them will give me an array of ‘paid\_invoices’ that I will be  
able to parse later similar to  
\<%= check\_box\_tag ‘paid\_invoices’, ‘paid\_invoices[]’, false %\>  
would give me

Is there a way to popular an array of ‘hidden\_field’ elements for  
posting?

Craig

–  
This message has been scanned for viruses and  
dangerous content by MailScanner, and is  
believed to be clean.

| \<%=h (check\_due.supplier.suppname) %\> | \<%=h (check\_due.suppreference) %\> |

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [September 15, 2009, 2:21am UTC](https://www.ruby-forum.com/t/hidden-fields/175508/2 "2009-09-15T02:21:11Z")

</div>

Craig W. wrote:

> … because I don’t want them tampered with.

Then keep that info server-side.

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [September 15, 2009, 11:31pm UTC](https://www.ruby-forum.com/t/hidden-fields/175508/3 "2009-09-15T23:31:25Z")

</div>

On Tue, 2009-09-15 at 02:21 +0200, Ar Chron wrote:

> Craig W. wrote:
> 
> > … because I don’t want them tampered with.
> 
> Then keep that info server-side.

* * *

not sure what you mean by this.

do you mean put them into the session?

do you mean put them into a temporary storage table, perhaps identified  
by the session?

I ended up using hidden\_field\_tag just like I had to use check\_box\_tag  
to accomplish this by the way but I do need persistence of these arrays  
through several screens and I have to keep posting them and assigning  
them for each screen and perhaps there is a better way.

Craig

–  
This message has been scanned for viruses and  
dangerous content by MailScanner, and is  
believed to be clean.

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [September 16, 2009, 2:11am UTC](https://www.ruby-forum.com/t/hidden-fields/175508/4 "2009-09-16T02:11:32Z")

</div>

You could go with active\_record\_store for your session data.

Check out ActionController::Base at [http://api.rubyonrails.org/](http://api.rubyonrails.org/)
