Re: php processing name vs. id field

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 1 July 2010 15:02, Bob McConnell <rvm@xxxxxxxxx> wrote:
> From: Peter Lind
>
>> On 1 July 2010 14:38, Bob McConnell <rvm@xxxxxxxxx> wrote:
>>> From: Adam Richardson
>>>
>>>> On Wed, Jun 30, 2010 at 9:16 PM, David Mehler
> <dave.mehler@xxxxxxxxx>
>>> wrote:
>>>>
>>>>> Hello,
>>>>> I've got a php form processing question. I've got a text field like
>>> so:
>>>>>
>>>>> <div>
>>>>> <label for="txtname">Name*:</label>
>>>>> <input type="text" name="name" id="name" size="30" value="<?php
> echo
>>>>> htmlspecialchars($_POST['name']), ENT_QUOTES, UTF-8; ?>" /> <br />
>>>>> </div>
>>>>>
>>>>> My question is what is the purpose of the id field? I know the name
>>>>> field is what php references, but am not sure what id is for?
>>>>
>>>> Sometimes it's helpful to target a specific element for stylistic or
>>>> functional purposes, and that's when you'll find an id attribute
>>> helpful.
>>>>
>>>> In your example above, label elements use the id in the 'for'
>>> attribute
>>>> (and, speaking to your example, you should have for="name" instead
> of
>>>> for="txtname"):
>>>> http://www.w3schools.com/tags/tag_label.asp
>>>>
>>>> In terms of CSS, you can specifically reference the element by it's
> id
>>> using
>>>> the notation tag_name#id_value, and id's have the highest order of
>>>> specificity (i.e., if you try and style an element by tag name,
> class,
>>>> and/or id, the id styles are what will take precedent, all other
>>> things
>>>> equal.)
>>>> http://webdesign.about.com/od/cssselectors/qt/cssselid.htm
>>>> http://www.stuffandnonsense.co.uk/archives/css_specificity_wars.html
>>>>
>>>> In terms of javascript, you can reference the element by it's id by
>>> using
>>>> the function getElementById('id_value):
>>>> http://www.tizag.com/javascriptT/javascript-getelementbyid.php
>>>>
>>>> Just remember that a particular id can only occur once on a page
>>> (another
>>>> difference between the name attributes in a form, as you could have
>>> multiple
>>>> forms on a page and each form could have an input with a "zip" name
>>> without
>>>> issue, but that same page could only have one id with the value
>>> "zip".)
>>>>
>>>> That all said, with the advent of javascript data attributes, you'll
>>> have
>>>> one more way to target elements for design and functionality:
>>>> http://ejohn.org/blog/html-5-data-attributes/
>>>
>>> If you look at the current HTML 4.01 and XHTML 1.0 specification, you
>>> will find 'name' is no longer listed as a standard attribute. It is
> all
>>> but obsolete and has been replaced by 'id' almost everywhere. They
>>> actually recommend you put both attributes into tags with identical
>>> values until your applications can be updated to drop all uses of the
>>> name attribute.
>>>
>>> <http://www.w3schools.com/tags/default.asp>
>>>
>>
>> Errr, what? Name is by no means obsolete for forms. Have a look at
>>
> http://dev.w3.org/html5/spec/association-of-controls-and-forms.html#attr
> -fe-name
>> - it's still in the html5 spec and there's little to no chance of it
>> going away any time soon.
>
> HTML5 is years away from completion and still changes far too often, so
> we don't consider it nearly ready for prime time. XHTML is here now, has
> several usable validation suites and has been stable for years. That's
> more of a reasonable target for commercial products.
>
>> Relying on w3schools is not ... really advisable.
>
> Where else would you go? Even W3C doesn't publish decent reference
> documents, and their specifications are inscrutable to normal human
> beings.
>
> Bob McConnell
>



-- 
<hype>
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
</hype>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux