Forum Moderators: coopster
I have many forms on my site and so far just check to see if my vars have a value and if not just show a messages saying please fill out such and such a field.
What i want to do is, check that each form field has a value and for the ones that dont, send the appropriate error message or number to another script that displays the error messages. This way I have one error page used to display various errors from all forms of my site. So i need a way to send the error messages to the error page. Like an array then i can just iterate the error array to display each message.
Why the extra page? Cause i'm using a template that wont be easy to put directly into form processing scripts. It could be done but i would prefer a cleaner method.
Sorry if that was confusing
Thanks for any help
If you want to send data to another page, then you`ll probably need to pass it in a query string.
So, try something like this. Its not the best way I don`t suppose, but should work. Note that in using the header function this processing MUST go at the top of your script.
error = array();if ($name="")
{
$error[] = 'name=1';
}
if ($email=="")
{
$error[] = 'email=1';
}
if ($comments=="")
{
$error[] = 'comments=1';
}and so on..
Then create the error string if any errors are present:
if ($error)
{
//Build query string$for($i=0; $i<count($error); $i++)
{
if ($i)
{
$error_string .= '&' . $error[$i];
}
else
{
$error_string = $error[$i];
}
}header("Location: error.php?$error_string");
}
else
{
header("Location: thanks.php");
}
On your error.php page, display messages based on the query string.
if (isset($_GET['name']))
{
echo 'Please enter your name';
}
etc etc
Hope that helps.
dc
I am using error.php for over 20 forms of my site. What i do is just make my querie string like so:
header("Location: ../error.php?form=1&$error_string");
So for my login page has form=1 then my contact page has form=2 ect then i just switch($form) on the error page with each case being the proper error display code.