note 80201 deleted from tutorial.forms by danbrown
| From: | danbrown@php.net | Date: | Thu, 15 Jan 2009 03:49:53 +0000 |
| Subject: | note 80201 deleted from tutorial.forms by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-149229@lists.php.net to get a copy of this message | ||
Note Submitter: Lord Pacal
----
One thing that tripped me up when I was first learning PHP was the use of the NAME attribute in form
fields. The current convention is to use the ID attribute instead when creating forms. (Many HTML
editors automatically include an ID attribute without a NAME attribute.) Now, I include both the
NAME and ID attributes (with the same value) in all my form fields.
For example...
<form method="post">
<input type="text" id="field1">
<input type="submit" value="go">
</form>
If you then have a PHP page requesting the contents of the "field1" field...
<?php echo $_POST["field1"] ?>
...the above form will always return an empty string for "field1".
The solution is to include the NAME attribute...
<form method="post">
<input type="text" id="field1" name="field1">
<input type="submit" value="go">
</form>
With this change, the PHP code will correctly retrieve the value of the "field1" field.