Hello guys… I got the following code in a file named session.php which is included in the registration form and user edit profile form of my website…
When the user leaves the email field blank it drops an error and if they enter a wrong email address it drops an error. This works just FINE in both pages (registration and profile edit). So thats cool right there!
[php] /* Email error checking /
$field = “email”; //Use field name for email
if(!$subemail || strlen($subemail = trim($subemail)) == 0){
$form->setError($field, " Email not entered");
}
else{
/* Check if valid email address /
$regex = "^[+a-z0-9-]+(.[+a-z0-9-]+)"
."@[a-z0-9-]+(.[a-z0-9-]{1,})"
.".([a-z]{2,}){1}$";
if(!eregi($regex,$subemail)){
$form->setError($field, " Email invalid");
}
$subemail = stripslashes($subemail);
}
[/php]
Now, i noticed that if the username already exists it tell them that its already in use (just in the registration page, because i dont have the option to change username in the edit profile page):
[php]
/* Check if username is already in use /
else if($database->usernameTaken($subuser)){
$form->setError($field, " Username already in use");
}
[/php]
So it rang my bell and i said… hmmmmm if i copy that coding and replace the “username” and “user” with “email” it might tell the user that the email is already taken and it does!!!.. BUT the PROBLEM is that it only shows the error in the registration page and not in the user profile edit page as well… why???
This is what I have so far, after adding tha extra coding to see if the email already exists in the database:
[php]
/* Check if email is already in use /
$field = “email”; //Use field name for email
if($database->emailTaken($subemail)){
$form->setError($field, " Email already in use");
}
/* Email error checking /
$field = “email”; //Use field name for email
if(!$subemail || strlen($subemail = trim($subemail)) == 0){
$form->setError($field, " Email not entered");
}
else{
/* Check if valid email address /
$regex = "^[+a-z0-9-]+(.[+a-z0-9-]+)"
."@[a-z0-9-]+(.[a-z0-9-]{1,})"
.".([a-z]{2,}){1}$";
if(!eregi($regex,$subemail)){
$form->setError($field, " Email invalid");
}
$subemail = stripslashes($subemail);
}
[/php]
In case you are wondering how i display the errors, its by echo…
[php]<? echo $form->error("email"); ?>[/php]
Help me pleaseeeeeeeeeeeeeeeeeeeeeeeee