PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
darkfreaks
Forum Commoner
Posts: 59 Joined: Sat Sep 09, 2006 3:59 pm
Post
by darkfreaks » Sun Dec 10, 2006 11:08 pm
ok so i tried adding an email validation to my form
the actual function is in a file called func.php
so i included it in the php code then pasted this code. and it says undefined call to function?
Code: Select all
[syntax=php]include("functions.php");
$email = validateemail($_POST['email']);
if ($email == false) { $emailerror = "Email must be filled and valid.<br />"; }[/syntax][/quote]
Sloth
Forum Newbie
Posts: 18 Joined: Thu Dec 07, 2006 7:29 pm
Post
by Sloth » Sun Dec 10, 2006 11:27 pm
Check if validateemail is in your functions.php or if your script is actually finding the functions.php
Maybe you can try replacing the include by a require statement and see if any errors pop up
darkfreaks
Forum Commoner
Posts: 59 Joined: Sat Sep 09, 2006 3:59 pm
Post
by darkfreaks » Sun Dec 10, 2006 11:39 pm
the error i get is Fatal error: Call to undefined function: validateemail()
my function in func.php is :
Code: Select all
[syntax=php]//VALIDATE EMAIL
function validateemail($str) {
if (eregi("^[[]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$", $str) && strlen($str <= 255)) { return $str; }
else { return false; }
}[/syntax]
Sloth
Forum Newbie
Posts: 18 Joined: Thu Dec 07, 2006 7:29 pm
Post
by Sloth » Sun Dec 10, 2006 11:45 pm
try change
Code: Select all
include("functions.php");
$email = validateemail($_POST['email']);
if ($email == false) { $emailerror = "Email must be filled and valid.<br />"; }
to
Code: Select all
require("functions.php");
$email = validateemail($_POST['email']);
if ($email == false) { $emailerror = "Email must be filled and valid.<br />"; }
And see if it produces an error, if it does that means your functions.php file cannot be located (You might want to check up on file permissions too
)
darkfreaks
Forum Commoner
Posts: 59 Joined: Sat Sep 09, 2006 3:59 pm
Post
by darkfreaks » Mon Dec 11, 2006 12:03 am
now its not giving me anything it just skips over the validation woiwdew' *bangs head on desk*
Sloth
Forum Newbie
Posts: 18 Joined: Thu Dec 07, 2006 7:29 pm
Post
by Sloth » Mon Dec 11, 2006 12:18 am
maybe you could try replace the validateemail function with this
Code: Select all
function validate($email) {
preg_match_all('/^[a-zA-Z][\\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/', $email, $match);
if (!empty($match[0][0]) && (strlen($email) <= 255))) {
return $match[0][0];
} else {
return false;
}