# Fields\_for adding html (text) for hidden field

**URL:** <https://discuss.rubyonrails.org/t/fields-for-adding-html-text-for-hidden-field/62428>\
**Category:** rubyonrails-talk\
**Created:** [January 20, 2012, 2:01pm UTC](https://discuss.rubyonrails.org/t/fields-for-adding-html-text-for-hidden-field/62428 "2012-01-20T14:01:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [January 20, 2012, 2:01pm UTC](https://discuss.rubyonrails.org/t/fields-for-adding-html-text-for-hidden-field/62428/1 "2012-01-20T14:01:22Z")

</div>

Hello all,

I'm getting this weird '\<input name value='2' type='hidden' /\>' text printed out in my form. See attached image. I've spent too much time trying to figure it out already and it's not going to stop me from moving on for now.

As you can see it's still very early on.

I'm using nested\_attributes\_for and fields\_for: (also HAML)

---

<div class="post-metadata">

**Author:** ![Colin\_Law1](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Colin\_Law1](https://discuss.rubyonrails.org/u/Colin_Law1)\
**Post date:** [January 20, 2012, 2:09pm UTC](https://discuss.rubyonrails.org/t/fields-for-adding-html-text-for-hidden-field/62428/2 "2012-01-20T14:09:28Z")

</div>

That sort of thing is often caused by invalid html. Try copying the full page source (probably right click View Source in the browser) and pasting it into the w3c html validator.

Colin

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [January 21, 2012, 3:46am UTC](https://discuss.rubyonrails.org/t/fields-for-adding-html-text-for-hidden-field/62428/3 "2012-01-21T03:46:11Z")

</div>

Hai!

# you can try this way:

\<%= form\_for :module\_name do |form| %\>

\<%= form.hidden\_field :name,:value=\>'2'%\>

\<%end%\>

# controller side you can get like this way

&nbsp;&nbsp;params[:user]

Bye:) bdeveloper01

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [May 22, 2012, 7:34pm UTC](https://discuss.rubyonrails.org/t/fields-for-adding-html-text-for-hidden-field/62428/4 "2012-05-22T19:34:02Z")

</div>

Hey, this should do the trick:

= form\_for @user, :url =\> {:action =\> 'update'} do |f| &nbsp;&nbsp;= f.fields\_for :roles do |r| &nbsp;&nbsp;&nbsp;&nbsp;- if r.object.for\_object.present? &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= r.label :role, r.object.for\_object.name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= r.select :role, Role::Roles.options\_for\_select &nbsp;&nbsp;&nbsp;&nbsp;- else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;="" &nbsp;&nbsp;= f.submit "Update User"
