PHP Implementation of Select Violates HTML Standard

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: PHP Implementation of Select Violates HTML Standard

Post by Eran »

Also notice that using this syntax you can create multi-dimensional arrays, which you can't do using same-named variables. You can also specify the array indexes. I have used this feature several times to great effect, and it is quite powerful as christopher puts it.
André D
Forum Commoner
Posts: 55
Joined: Thu Aug 28, 2008 7:03 pm

Re: PHP Implementation of Select Violates HTML Standard

Post by André D »

Jcobban, it sounds as if you've changed your argument. [EDIT: See edit below] If I am misunderstanding you, please clarify. I thought you were originally displeased by the use of [] bracket characters in the value of a select element's name attribute.
jcobban wrote:However if I code the HTML as:

Code: Select all

<select name='fruit[]' multiple='multiple'>
<option value='A'>Apple</option>                           
<option value='B'>Banana</option>                          
<option value='C'>Cherry</option>                          
</select>
then the multiple values are passed to the web server as "...?fruit[]=A&fruit[]=B&fruit[]=C". In the PHP script the value of $_GET['fruit'] is the array {"A", "B", "C"}.
But later you said you're not concerned about the characters used but the case-sensitivity of it?
Weirdan wrote:Where PHP goes somewhat against the spec is not the set of characters used in name attribute, but the fact that it treats incoming parameters as case sensitive whereas user agents should treat form field names in case-insensitive manner
[EDIT: I accidentally quoted Weirdan here and mistreated his statement as if it were said by jcobban. Hence my confusion.]

As far as the use of [] bracket characters, as has already been stated, the piece of the HTML spec you quoted about the ID and NAME tokens does not apply to your argument; it is erroneous. From the HTML 4 Document Type Definition:
http://www.w3.org/TR/html401/sgml/dtd.html wrote:[text]<!ELEMENT SELECT - - (OPTGROUP|OPTION)+ -- option selector -->
<!ATTLIST SELECT
%attrs; -- %coreattrs, %i18n, %events --
name CDATA #IMPLIED -- field name --
size NUMBER #IMPLIED -- rows visible --
multiple (multiple) #IMPLIED -- default is single selection --
disabled (disabled) #IMPLIED -- unavailable in this context --
tabindex NUMBER #IMPLIED -- position in tabbing order --
onfocus %Script; #IMPLIED -- the element got the focus --
onblur %Script; #IMPLIED -- the element lost the focus --
onchange %Script; #IMPLIED -- the element value was changed --
%reserved; -- reserved for possible future use --
>[/text]
Clearly, the name attribute of a select holds values of type CDATA, not NAME.

Regarding the case-sensitivity issue you raise, [EDIT: Actually Weirdan. See above.] I would argue that PHP does not need to implement any markup language spec at all (HTML 4, XHTML 1.1, etc.); that's a different layer. The server-side (e.g., Apache/PHP) is responding to HTTP requests. HTTP is defined in other specifications which are not tightly coupled to HTML or any specific markup language. I couldn't find any relevant specs or RFCs that describe whether query string or application/x-www-form-urlencoded name=value pairs should be interpreted in a case-sensitive manner or not. I could be wrong on that.

If you don't like how PHP does this, why don't you refrain from using the $_GET superglobal and just parse the $_SERVER['QUERY_STRING'] value manually? (Or read the php://input stream for raw POST data.) This way you can interpret duplicate parameters and letter case however you wish! Problem solved.

Lastly, you should read about web application parameter pollution to learn just how jumbled the interpretation of request parameters across various back-end platforms really is. IMHO PHP's behavior is very reasonable compared to other platforms.
Last edited by André D on Mon Apr 05, 2010 8:31 pm, edited 2 times in total.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: PHP Implementation of Select Violates HTML Standard

Post by Weirdan »

AbraCadaver wrote:Are you agreeing with me or disagreeing, I can't tell?
Merely quoting your post and expanding on what you said. My post was addressed to OP if you didn't notice :wink:
André D wrote:[to jcobban] But later you said you're not concerned about the characters used but the case-sensitivity of it? [ followed by the quote from my post ]
Guys, I get the impression you don't read what you're replying to. :evil:
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: PHP Implementation of Select Violates HTML Standard

Post by josh »

jcobban wrote:Aside from programming conventions none of the contributors to this thread have advanced any extra-ordinary reasons for this implementation, nor found inadequacies in my suggested alternative implementations.
Nor have you, provided any "extra-ordinary" reasons on why the syntax is "bad". Nor have you found inadequacies in the existing solution. So right back at you.

Your argument is basically "i like it this way".
André D
Forum Commoner
Posts: 55
Joined: Thu Aug 28, 2008 7:03 pm

Re: PHP Implementation of Select Violates HTML Standard

Post by André D »

Weirdan wrote:Guys, I get the impression you don't read what you're replying to.
You're right; sorry. I got confused and thought your post was by jcobban. It may have been the emboldened "jcobban" you opened with. My fault.

Either way, my main point is still relevant as is my proposed solution to jcobban's problem.
Post Reply