Page 1 of 1

Empty HTML 4.01 form 'action' attribute - valid?

Posted: Sun Aug 16, 2009 5:37 am
by AlexC
Morning,

I pretty much always give the 'action' attribute a value that I need, however I wonder if I really do need to - as I know browsers will accept a blank value. Now, looking at the RFCs and HTML 4.01 spec, it is not entirely clear if this is valid, or just a quirk that browsers have decided to do.

http://www.w3.org/TR/html401/types.html#type-uri states that:
This specification uses the term URI as defined in [URI] (see also [RFC1630]).
Now, RFC1630 does not mention anything about empty URIs as being a valid URI - however, RFC2396 (http://www.ietf.org/rfc/rfc2396.txt) does specify that empty URIs are valid - and even has an exception for HTML 'form element:
4.2. Same-document References wrote: A URI reference that does not contain a URI is a reference to the
current document. In other words, an empty URI reference within a
document is interpreted as a reference to the start of that document,
and a reference containing only a fragment identifier is a reference
to the identified fragment of that document. Traversal of such a
reference should not result in an additional retrieval action.
However, if the URI reference occurs in a context that is always
intended to result in a new request, as in the case of HTML's FORM
element, then an empty URI reference represents the base URI of the
current document and should be replaced by that URI when transformed
into a request.
1630 does not say an empty URI is valid, and this is what the HTML spec uses - however it also doesn't say if it is not valid. So I'm quite confused as to what the expected behaviour is for HTML forms. Is it safe to use an empty 'action' attribute?

Re: Empty HTML 4.01 form 'action' attribute - valid?

Posted: Sat Aug 22, 2009 7:48 am
by AlexC
Anyone have any ideas? :)

Re: Empty HTML 4.01 form 'action' attribute - valid?

Posted: Sat Aug 22, 2009 8:00 am
by jackpf
Well, from what you posted, it looks valid. Although just to be sure, you could always stick

Code: Select all

htmlentities($_SERVER['REQUEST_URI'])
in there :)

Re: Empty HTML 4.01 form 'action' attribute - valid?

Posted: Sat Aug 22, 2009 8:04 am
by AlexC
I've already got mechanisms in place to create the correct action value required, just would be so much easier to do action="" and know it is valid. But yeah, it does look like it is valid, just no solid proof in black/white to say so, which sucks :P

Re: Empty HTML 4.01 form 'action' attribute - valid?

Posted: Sat Aug 22, 2009 3:26 pm
by Darhazer
I'm using action="?" to post to same script and it works perfectly.
Never tried with empty action however

Re: Empty HTML 4.01 form 'action' attribute - valid?

Posted: Sat Aug 22, 2009 7:02 pm
by jackpf
Aha, but what happens if there's a query string in the current uri? Your method would break the query string surely...

Re: Empty HTML 4.01 form 'action' attribute - valid?

Posted: Sun Aug 23, 2009 7:11 am
by Darhazer
jackpf wrote:Aha, but what happens if there's a query string in the current uri? Your method would break the query string surely...
The parameters that have to been preserved, are put into state, and others are discarded. But this is another topic.