Display errors
Moderator: General Moderators
Display errors
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.....
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.....
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.
?>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;?
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;?
-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA
Whats wrong with just adding a string?tim wrote:turn the errors into an array
if (condiction) {
$error[] = "error 1";
}
if (condiction2) {
$error[] = "error 2";
}
etc
foreach() then
Code: Select all
$errors .= "You didn't enter a username!<br />\n";-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA