Page 1 of 1
Display errors
Posted: Sun Jun 20, 2004 6:49 am
by ddragas
Hi
How to display errors in same page where form is.
Errors are validation if user has input certan fields of form
exsample:
if ($name="" echo "You didn't input your name";
if ($email="" echo "You didn't input your email";
etc.....
Posted: Sun Jun 20, 2004 9:15 am
by tim
Code: Select all
<?php
if (empty($username_text_field_name)) {
echo "error, fill in username";
}
etc
and use $_SERVER['PHP_SELF']; to get it to stay on the same page, but just send it to a different page to validate. I dont get the jist of PHP_SELF, when you can create another small file and go thru less hassel.
?>
Posted: Sun Jun 20, 2004 1:45 pm
by ddragas
ok
and how to display all errors together.
Should I put all errors in one variable?
example
$error='
if (empty($username_text_field_name)) {
echo "error, fill in username". "<br>\n";
}
if (empty($Last_name)) {
echo "error, fill in last name". "<br>\n";
}
if (empty($email)) {
echo "error, fill in email". "<br>\n";
}'
and then sendit to first page where form is with
$_POST['error'];
and later
echo $error;?
Posted: Sun Jun 20, 2004 1:50 pm
by feyd
I handle form processing in the page with the form, until everything is valid, then it redirects or whatever to the "success" page.
Posted: Sun Jun 20, 2004 2:05 pm
by tim
turn the errors into an array
if (condiction) {
$error[] = "error 1";
}
if (condiction2) {
$error[] = "error 2";
}
etc
foreach() then
Posted: Sun Jun 20, 2004 2:40 pm
by d3ad1ysp0rk
tim wrote:turn the errors into an array
if (condiction) {
$error[] = "error 1";
}
if (condiction2) {
$error[] = "error 2";
}
etc
foreach() then
Whats wrong with just adding a string?
Code: Select all
$errors .= "You didn't enter a username!<br />\n";
Posted: Sun Jun 20, 2004 4:41 pm
by tim
that would be the simpler route to take
But i like mine better,

Posted: Sun Jun 20, 2004 6:26 pm
by d3ad1ysp0rk
Well.. uh.. I like mine more!
End of discussion.
I win.
Posted: Sun Jun 20, 2004 7:54 pm
by tim
okay
Posted: Mon Jun 21, 2004 5:26 am
by ddragas
thank you guys