Forum: Ruby on Rails What is the reason that the authenticity_token hidden field gets wrapped in a DIV?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2505b282d57c29be797dc35b245adb4c?d=identicon&s=25 Philip Hallstrom (Guest)
on 2009-04-21 21:26
(Received via mailing list)
Hi all -

This has never been an issue for me until today.  However I have a
form and Rails is inserting it's hidden authenticity_token field.  It
wraps it in a div with a style.  And doing that messes things up for
me CSS wise.

Which got me to thinking about why it's wrapped at all?  Hidden fields
don't take up any room.  Why wrap it in a div which can have some side
affects?  And if we're going to wrap it, why not at least give it a
class so we can target it and set display:none which fixes the problem.

Can anyone shed some light on why this is the case?  If there's no
good reason it seems like the wrapped div should go away shouldn't it?


<form action="xxx" method="post">
   <div style="margin:0;padding:0"><input name="authenticity_token"
type="hidden" value="xxxxx=" /></div>
   <input id="q" name="q" type="text" />
   <input src="search.png" type="image" />
</form>

-philip
2505b282d57c29be797dc35b245adb4c?d=identicon&s=25 Philip Hallstrom (Guest)
on 2009-04-21 22:22
(Received via mailing list)
Following up.  Looks like I'm not the only one who doesn't like this...

https://rails.lighthouseapp.com/projects/8994-ruby...
Ec5a599777854c540fd102ef4691fe10?d=identicon&s=25 Rimantas Liubertas (Guest)
on 2009-04-22 12:31
(Received via mailing list)
> Can anyone shed some light on why this is the case?  If there's no
> good reason it seems like the wrapped div should go away shouldn't it?

> <form action="xxx" method="post">
>   <div style="margin:0;padding:0"><input name="authenticity_token"
> type="hidden" value="xxxxx=" /></div>
>   <input id="q" name="q" type="text" />
>   <input src="search.png" type="image" />
> </form>

According to (X)HTML specification you cannot have inline elements
inside form, so inputs
must be wrapped in something: fieldset, p or div.

Regards,
Rimantas
--
http://rimantas.com/
2505b282d57c29be797dc35b245adb4c?d=identicon&s=25 Philip Hallstrom (Guest)
on 2009-04-22 17:58
(Received via mailing list)
>
> According to (X)HTML specification you cannot have inline elements
> inside form, so inputs
> must be wrapped in something: fieldset, p or div.

Ah, that would explain it then!  Thanks.  To anyone else who has
issues with this and CSS, check out the below patch.  It works great
on 2.3.2.  Basically I can override the style and set it to
display:none or display:inline...

https://rails.lighthouseapp.com/projects/8994-ruby...
This topic is locked and can not be replied to.