htmlformspost

HTML Forms - Are name and id required?


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?


Solution

  • 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">