note 80201 added to tutorial.forms
| From: | LordPacal at osu1 dot php dot net | Date: | Fri, 04 Jan 2008 02:38:17 +0000 |
| Subject: | note 80201 added to tutorial.forms | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-134752@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 209.41.74.194
Probable Submitter: 131.107.0.101
----
Manual Page -- http://www.php.net/manual/en/tutorial.forms.php
Edit -- https://master.php.net/note/edit/80201
Del: integrated -- https://master.php.net/note/delete/80201/integrated
Del: useless -- https://master.php.net/note/delete/80201/useless
Del: bad code -- https://master.php.net/note/delete/80201/bad+code
Del: spam -- https://master.php.net/note/delete/80201/spam
Del: non-english -- https://master.php.net/note/delete/80201/non-english
Del: in docs -- https://master.php.net/note/delete/80201/in+docs
Del: other reasons-- https://master.php.net/note/delete/80201
Reject -- https://master.php.net/note/reject/80201
Search -- https://master.php.net/manage/user-notes.php