Alex Rivera | Logout

HTML Forms - Are name and id required?

Asked 2010-06-16T07:52:18.660
30

Why do I need the name and id attributes for <input> form elements?

Which is used for POST data sending and which can I exclude?

Edit
Report

2 Answers

31

name is used by the server-side. This is necessary if you plan to process the field. id is only so label elements, when clicked and accessed by screen-readers, can trigger/invoke the form controls (inputs and selects).

<form method=POST action="form-processor.php">
    <input name=first_name value=john>
</form>

results in

$_POST = array('first_name' => 'john');

If the method is GET, it's appended to the query string:

http://site-name.com/form-handler.php?first_name=john

It's popular for query string appending with hidden inputs:

<input type="hidden" name="q" value="1">

answered 2010-06-16T07:53:52.540
0

name is needed for POST and GET... but not id... id is used for client-side processing.

answered 2010-06-16T07:54:10.450

Your Answer