Why does PHP not use id tags?
That's not PHP, that's HTML. PHP has nothing to do with the HTML spec.
HTML does use id
attributes, but it uses them for a different purpose than name
attributes.
HTML form
elements build requests (POST
or GET
generally) from their child value-carrying elements (input
, select
, textarea
, etc.). The name
attribute is used as the key, and the value
(or selected value, etc.) is used as the value.
This creates the key/value pairs for the data in the request.
There seems to be a lot of waste in having to duplicate the same string for both the id and name of an element within a form
You don't have to duplicate it. You may personally choose to duplicate it. But that's your choice. There's no rule in any specs/standards/conventions/etc. indicating that you must or even should do that.
<input id="foo" /> <!-- JS/CSS accept this -->
<!--- incorrect. JS/CSS can also target name attributes if necessary. -->
<input name="foo" /> <!-- Only PHP accepts this -->
<!--- incorrect. This isn't PHP, this is HTML. PHP isn't involved here at all. -->
<input id="foo" name="foo" /> <!-- Everyone's happy -->
<!--- if that's the markup you choose to define, sure. -->