method

hidden_field_tag

rails latest stable - Class: ActionView::Helpers::FormTagHelper
hidden_field_tag(name, value = nil, options = {})
public

Creates a hidden form input field used to transmit data that would be lost due to HTTP’s statelessness or data that should be hidden from the user.

Options

  • Creates standard HTML attributes for the tag.

Examples

hidden_field_tag 'tags_list'
# => <input type="hidden" name="tags_list" id="tags_list" autocomplete="off" />

hidden_field_tag 'token', 'VUBJKB23UIVI1UU1VOBVI@'
# => <input type="hidden" name="token" id="token" value="VUBJKB23UIVI1UU1VOBVI@" autocomplete="off" />

hidden_field_tag 'collected_input', '', onchange: "alert('Input collected!')"
# => <input type="hidden" name="collected_input" id="collected_input"
     value="" onchange="alert('Input collected!')" autocomplete="off" />

3Notes

hidden field can be changed by JS

HeeL · Dec 8, 20111 thank

Plumba, it's not that useless if you think about possibility to change a hidden field with JS

Storing array values

jebin · Jan 16, 20141 thank

I tried to add a array value using hidden_field_tag and access it in jquery. It just returns the flattened version of array. eg:(If i try to store [1,[1,2,3]] in hidden_field_tag , in jquery iam just getting '1 1 2 3') but if i use input field with type=hidden iam getting the correct value. Why is that?

onchange attribute on a hidden field is useless

plumba · Feb 7, 2011

In the third example there is no sense to set onchange event since it will never happen...