From: Peter Lind on
On 1 July 2010 15:02, Bob McConnell <rvm(a)cbord.com> wrote:
> From: Peter Lind
>
>> On 1 July 2010 14:38, Bob McConnell <rvm(a)cbord.com> wrote:
>>> From: Adam Richardson
>>>
>>>> On Wed, Jun 30, 2010 at 9:16 PM, David Mehler
> <dave.mehler(a)gmail.com>
>>> 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>
From: Peter Lind on
On 1 July 2010 15:28, Peter Lind <peter.e.lind(a)gmail.com> wrote:
> On 1 July 2010 15:02, Bob McConnell <rvm(a)cbord.com> wrote:
>> From: Peter Lind
>>
>>> On 1 July 2010 14:38, Bob McConnell <rvm(a)cbord.com> wrote:
>>>> From: Adam Richardson
>>>>
>>>>> On Wed, Jun 30, 2010 at 9:16 PM, David Mehler
>> <dave.mehler(a)gmail.com>
>>>> 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
>>

Sorry about the empty mail, a mistake.

Apart from that, html5 is not going to do away with the name
attribute. And name is in xhtml1 and html4.01 and there's no mention
of it being obsolete, deprecated or in any other fashion on the way
out.

As far as reference: the source.
http://www.w3.org/TR/xhtml1/dtds.html#a_dtd_XHTML-1.0-Strict very
clearly specifies that name is still a very valid attribute.
http://www.w3.org/TR/html401/interact/forms.html#h-17.4 shows the same
in a slightly more readable format - the only mentions of anything
deprecated (there are no references to anything obsolete) are for the
isindex element and the align attribute of the legend element.

What is the case regarding the name attribute is that it's been
deprecated for a few elements (such as a, form, frame, img) in XHTML1
and will be removed in XHTML2 (which we'll likely never see used in
browsers). See http://www.w3.org/TR/xhtml1/#h-4.10

Regards
Peter

--
<hype>
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
</hype>
From: Paul M Foster on
On Thu, Jul 01, 2010 at 03:40:56PM +0200, Peter Lind wrote:

<snip>

> Apart from that, html5 is not going to do away with the name
> attribute. And name is in xhtml1 and html4.01 and there's no mention
> of it being obsolete, deprecated or in any other fashion on the way
> out.
>
> As far as reference: the source.
> http://www.w3.org/TR/xhtml1/dtds.html#a_dtd_XHTML-1.0-Strict very
> clearly specifies that name is still a very valid attribute.
> http://www.w3.org/TR/html401/interact/forms.html#h-17.4 shows the same
> in a slightly more readable format - the only mentions of anything
> deprecated (there are no references to anything obsolete) are for the
> isindex element and the align attribute of the legend element.
>
> What is the case regarding the name attribute is that it's been
> deprecated for a few elements (such as a, form, frame, img) in XHTML1
> and will be removed in XHTML2 (which we'll likely never see used in
> browsers). See http://www.w3.org/TR/xhtml1/#h-4.10

All this is fortunate, since I don't think PHP is even aware of the ID
attribute. Imagine trying to process form fields without the "name"
attribute being present.

Paul

--
Paul M. Foster
From: Ashley Sheridan on
On Thu, 2010-07-01 at 10:19 -0400, Paul M Foster wrote:

> On Thu, Jul 01, 2010 at 03:40:56PM +0200, Peter Lind wrote:
>
> <snip>
>
> > Apart from that, html5 is not going to do away with the name
> > attribute. And name is in xhtml1 and html4.01 and there's no mention
> > of it being obsolete, deprecated or in any other fashion on the way
> > out.
> >
> > As far as reference: the source.
> > http://www.w3.org/TR/xhtml1/dtds.html#a_dtd_XHTML-1.0-Strict very
> > clearly specifies that name is still a very valid attribute.
> > http://www.w3.org/TR/html401/interact/forms.html#h-17.4 shows the same
> > in a slightly more readable format - the only mentions of anything
> > deprecated (there are no references to anything obsolete) are for the
> > isindex element and the align attribute of the legend element.
> >
> > What is the case regarding the name attribute is that it's been
> > deprecated for a few elements (such as a, form, frame, img) in XHTML1
> > and will be removed in XHTML2 (which we'll likely never see used in
> > browsers). See http://www.w3.org/TR/xhtml1/#h-4.10
>
> All this is fortunate, since I don't think PHP is even aware of the ID
> attribute. Imagine trying to process form fields without the "name"
> attribute being present.
>
> Paul
>
> --
> Paul M. Foster
>


Not sure if my other email got through earlier. Replacing the name
attribute on form fields with the id one is not feasible at all. They
don't even behave the same. What would happen if you had two forms on a
page that both had an element with the same name? Using the name
attribute, everything is fine, but not so if you were using the id
instead.

Going further, what about form elements sent as an array? I don't think
the id attribute is set up to follow any sort of array format (bearing
in mind also that it's only PHP that uses the [] suffix to denote a form
element be sent as an array). Doing so would break the functionality of
many pages today (no longer would DOM functions such as getElementByID()
work anymore because you'd be retrieving potentially more than one
element, so code like document.getElementById('element').style.something
wouldn't work.

Either way, the id attribute is not, and dare I say doesn't ever look to
be, a substitute for the name attribute on form elements.

Thanks,
Ash
http://www.ashleysheridan.co.uk


From: "Bob McConnell" on
From: Ashley Sheridan

> Not sure if my other email got through earlier. Replacing the name
> attribute on form fields with the id one is not feasible at all. They
> don't even behave the same. What would happen if you had two forms on
a
> page that both had an element with the same name? Using the name
> attribute, everything is fine, but not so if you were using the id
> instead.

These conditions sound like a bugs to me. I can't imagine any reason why
different forms could have the same name or id. That applies to any set
of elements on a page. Each one must have a unique moniker, no matter
which attribute you use. Even the simple validations I use will complain
about your duplicates, as they should. Making them all unique also makes
it much simpler to use tools like Selenium or Silk Test to automate the
testing process.

Looking at the HTML 4.01 references given earlier in this thread, I see
that id is now a core attribute, i.e. it is available for all but a
handful of tags, while name is only available for the tags where it is
explicitly included. So it still appears to me that id is the preferred
attribute, as it is more generally available.

Bob McConnell
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5
Prev: Past discussion
Next: Integers