Hidden method tag should be in <p>

Hi,

I'm unable to register with Trac (disk space full, as you already
know), and this is so silly it's barely worth registering for. I was
validating my pages as XHTML 1.0 Strict, and I got the following error:
   1. Error Line 27 column 88: document type does not allow element
"input" here; missing one of "p", "h1", "h2", "h3", "h4", "h5", "h6",
"div", "pre", "address", "fieldset", "ins", "del" start-tag.

      ...me="_method" type="hidden" value="" />

      The mentioned element is not allowed to appear in the context in
which you've placed it; the other mentioned elements are the only ones
that are both allowed there and can contain the element mentioned. This
might mean that you need a containing element, or possibly that you've
forgotten to close a previous element.

      One possible cause for this message is that you have attempted to
put a block-level element (such as "<p>" or "<table>") inside an inline
element (such as "<a>", "<span>", or "<font>").

Simply adding "<p>" and "</p>" around <input name="_method"
type="hidden" value="" /> makes it valid XHTML 1.0 Strict; see the
(extremely little simple) patch below.

PS. My apologies if this should have been posted on -talk, I guess I
think of -talk as "using rails" and -core as "developing rails". If
-core is "where the core developers talk about rails", I'm totally in
the wrong place. :slight_smile:

Index: actionpack/lib/action_view/helpers/form_tag_helper.rb

I'd use a div instead of a p, so as not to create undesirable margins.

Good point. Also, it shouldn't create tags when they're not needed
(when there is no method tag), so this patch would be better:

Index: actionpack/lib/action_view/helpers/form_tag_helper.rb

This is an awful idea. Generate a <div /> for each hidden element? What
a pointless waste. Wrap them all in one <div />, or as the freakin'
validator put right in front of you, the form-meaningful <fieldset />.

Joel Wilsson wrote:

Seth Thomas Rasmussen wrote:

This is an awful idea. Generate a <div /> for each hidden element? What
a pointless waste. Wrap them all in one <div />, or as the freakin'
validator put right in front of you, the form-meaningful <fieldset />.

It wouldn't be a div for each hidden element, it would be a div for
-the- hidden method tag created for SimplyRESTful links not using GET
or POST.

I can (and did) wrap other hidden fields in div tags on my own, but I
couldn't do that with this field, which seemed wrong. I tried putting a
div around all of it, and it still didn't validate.

Now I just tried putting a fieldset around it all, and it still gives
me the same error. It could very well just be me - I'm not experienced
with HTML. I tried this snippet:
<fieldset>
<%= error_messages_for("character") %>
<%= start_form_tag({ :action => :update }, { :method => :put }) %>
<div>
<%= select("character", "active", [["Active", true], ["Inactive",
false]]) %>
</div>
<%= end_form_tag %>
</fieldset>

Putting that fieldset in or taking it out makes no difference.
The validator still complains about the hidden method tag. It produces
the following HTML:
<fieldset>
<form action="/characters/2" method="post"><input name="_method"
type="hidden" value="put" />
<div>
<select id="character_active" name="character[active]"><option
value="true" selected="selected">Active</option>
<option value="false">Inactive</option></select>
</div>
</form>
</fieldset>

This doesn't validate, and I thought that something so simple should.
It's quite possible that I'm doing something wrong, and I'm not
obsessive about getting this to validate, so I'll just drop the
subject.

I was only trying to help, and I did my best to try the suggestions
given to me by the "freakin' validator" and it didn't work, while
putting a div around the hidden method did... I'm sorry I wasted your
time with this "awful idea" and "pointless waste".

Joel Wilsson wrote:

It wouldn't be a div for each hidden element, it would be a div for
-the- hidden method tag created for SimplyRESTful links not using GET
or POST.

I can (and did) wrap other hidden fields in div tags on my own, but I
couldn't do that with this field, which seemed wrong. I tried putting a
div around all of it, and it still didn't validate.

Now I just tried putting a fieldset around it all, and it still gives
me the same error. It could very well just be me - I'm not experienced
with HTML. I tried this snippet:
<fieldset>
<%= error_messages_for("character") %>
<%= start_form_tag({ :action => :update }, { :method => :put }) %>
<div>
<%= select("character", "active", [["Active", true], ["Inactive",
false]]) %>
</div>
<%= end_form_tag %>
</fieldset>

Putting that fieldset in or taking it out makes no difference.
The validator still complains about the hidden method tag. It produces
the following HTML:
<fieldset>
<form action="/characters/2" method="post"><input name="_method"
type="hidden" value="put" />
<div>
<select id="character_active" name="character[active]"><option
value="true" selected="selected">Active</option>
<option value="false">Inactive</option></select>
</div>
</form>
</fieldset>

This doesn't validate, and I thought that something so simple should.
It's quite possible that I'm doing something wrong, and I'm not
obsessive about getting this to validate, so I'll just drop the
subject.

I was only trying to help, and I did my best to try the suggestions
given to me by the "freakin' validator" and it didn't work, while
putting a div around the hidden method did... I'm sorry I wasted your
time with this "awful idea" and "pointless waste".
  

I think the validator complained about your HTML because the div and fieldset tags were outside of the form element. If the generate HTML instead looked like this:

<form action="/characters/2" method="post">
<fieldset>
<input name="_method"
type="hidden" value="put" />
<div>
<select id="character_active" name="character[active]"><option
value="true" selected="selected">Active</option>
<option value="false">Inactive</option></select>
</div>
</fieldset>
</form>

I think it would validate. However, this obviously isn't possible without editing the method, because the method generates the form tag as well. I think your solution (wrapping the hidden input with divs) is perfectly good, although perhaps fieldset would be more appropriate.

Joel Wilsson wrote:

Seth Thomas Rasmussen wrote:
> This is an awful idea. Generate a <div /> for each hidden element? What
> a pointless waste. Wrap them all in one <div />, or as the freakin'
> validator put right in front of you, the form-meaningful <fieldset />.

It wouldn't be a div for each hidden element, it would be a div for
-the- hidden method tag created for SimplyRESTful links not using GET
or POST.

That's what I get for not reading carefully. Even if it would have been
on topic, the response was unecessarily harsh. My apologies, sir.

For what it's worth, now that I'm paying attention, this is a perfectly
fine idea.