note 87512 added to reserved.variables.post
| From: | paulatyoungishdothomelinux^org at osu1 dot php dot net | Date: | Mon, 08 Dec 2008 09:09:56 +0000 |
| Subject: | note 87512 added to reserved.variables.post | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-147907@lists.php.net to get a copy of this message | ||
For a page with multiple forms here is one way of processing the different POST values that you may
receive. This code is good for when you have distinct forms on a page. Adding another form only
requires an extra entry in the array and switch statements.
<?php
if (!empty($_POST))
{
// Array of post values for each different form on your page.
$postNameArr = array('F1_Submit', 'F2_Submit', 'F3_Submit');
// Find all of the post identifiers within $_POST
$postIdentifierArr = array();
foreach ($postNameArr as $postName)
{
if (array_key_exists($postName, $_POST))
{
$postIdentifierArr[] = $postName;
}
}
// Only one form should be submitted at a time so we should have one
// post identifier. The die statements here are pretty harsh you may consider
// a warning rather than this.
if (count($postIdentifierArr) != 1)
{
count($postIdentifierArr) < 1 or
die("\$_POST contained more than one post identifier: " .
implode(" ", $postIdentifierArr));
// We have not died yet so we must have less than one.
die("\$_POST did not contain a known post identifier.");
}
switch ($postIdentifierArr[0])
{
case 'F1_Submit':
echo "Perform actual code for F1_Submit.";
break;
case 'Modify':
echo "Perform actual code for F2_Submit.";
break;
case 'Delete':
echo "Perform actual code for F3_Submit.";
break;
}
}
else // $_POST is empty.
{
echo "Perform code for page without POST data. ";
}
?>
----
Server IP: 66.207.199.35
Probable Submitter: 96.49.79.192
----
Manual Page -- http://www.php.net/manual/en/reserved.variables.post.php
Edit -- https://master.php.net/note/edit/87512
Del: integrated -- https://master.php.net/note/delete/87512/integrated
Del: useless -- https://master.php.net/note/delete/87512/useless
Del: bad code -- https://master.php.net/note/delete/87512/bad+code
Del: spam -- https://master.php.net/note/delete/87512/spam
Del: non-english -- https://master.php.net/note/delete/87512/non-english
Del: in docs -- https://master.php.net/note/delete/87512/in+docs
Del: other reasons-- https://master.php.net/note/delete/87512
Reject -- https://master.php.net/note/reject/87512
Search -- https://master.php.net/manage/user-notes.php