note 25423 deleted from function.session-register by sniper
| From: | sniper@php.net | Date: | Thu, 31 Oct 2002 00:47:31 +0000 |
| Subject: | note 25423 deleted from function.session-register by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-38785@lists.php.net to get a copy of this message | ||
The syntax involved in using $_SESSION when passing arrays between a validation page and a display
page (in my case an array of errors) , is not something which is immediately obvious.
If you do the following in,say, validation.php:
if (!session_is_registered("formErrs"))
session_register ("formErrs");
$formErrs=array();
$formErrs ["formName"] = "Error: Name cannot be blank";
you will then need to use the following format to retrieve the values in the main page.
$name="formName";
if (isset($_SESSION["formErrs"]["$name"])) {
echo "We've found " . $_SESSION ["formErrs"] ["$name"])
}
or alternately to just dump the array
foreach ($_SESSION["formErrs"] as $var=>$errText){
Echo "Debug: $var : $errText<br>\n";
}