I am having an issue (bug :/) with my validation for a contact form....when I try to enter the information into my form located here:
http://www.dcmedia-design.com/contact-us.html
I get an error telling me that there is a validation problem:
Warning: main(http://www.dcmedia-design.com/functions.php) [function.main]: failed to open stream: HTTP request failed! in /home3/danielp0/public_html/contact.php on line 15
Warning: main() [function.include]: Failed opening 'http://www.dcmedia-design.com/functions.php' for inclusion (include_path='.:/usr/lib64/php:/usr/lib/php') in /home3/danielp0/public_html/contact.php on line 15
Fatal error: Call to undefined function: validateemail() in /home3/danielp0/public_html/contact.php on line 38
..so with those, I have a contact.php form that has this:
<?php
/*
Credits: Bit Repository
URL: http://www.bitrepository.com/
*/
include 'http://www.dcmedia-design.com/config.php';
error_reporting (E_ALL ^ E_NOTICE);
$post = (!empty($_POST)) ? true : false;
if($post)
{
include 'http://www.dcmedia-design.com/functions.php';
$name = stripslashes($_POST['name']);
$email = trim($_POST['email']);
$subject = stripslashes($_POST['subject']);
$message = stripslashes($_POST['message']);
$error = '';
// Check name
if(!$name)
{
$error .= 'Please enter your name.<br />';
}
// Check email
if(!$email)
{
$error .= 'Please enter an e-mail address.<br />';
}
if($email && !ValidateEmail($email))
{
$error .= 'Please enter a valid e-mail address.';
}
// Check message (length)
if(!$message || strlen($message) < 1)
{
$error .= "Please enter your message.<br />";
}
if(!$error)
{
$mail = mail(WEBMASTER_EMAIL, $subject, $message,
"From: ".$name." <".$email.">\r\n"
."Reply-To: ".$email."\r\n"
."X-Mailer: PHP/" . phpversion());
if($mail)
{
echo 'OK';
}
}
else
{
echo '<div class="notification_error">'.$error.'</div>';
}
}
?>
and then a called file called function.php that shows this:
<?php
function ValidateEmail($email)
{
/*
(Name) Letters, Numbers, Dots, Hyphens and Underscores
(@ sign)
(Domain) (with possible subdomain(s) ).
Contains only letters, numbers, dots and hyphens (up to 255 characters)
(. sign)
(Extension) Letters only (up to 10 (can be increased in the future) characters)
*/
$regex = '/([a-z0-9_.-]+)'. # name
'@'. # at
'([a-z0-9.-]+){2,255}'. # domain & possibly subdomains
'.'. # period
'([a-z]+){2,10}/i'; # domain extension
if($email == '') {
return false;
}
else {
$eregi = preg_replace($regex, '', $email);
}
return empty($eregi) ? true : false;
}
?>
So another set of eyes on this would be helpful and GREAT!
Thank you!!!
PHP Validation Code...
Moderator: General Moderators
- Sofw_Arch_Dev
- Forum Commoner
- Posts: 60
- Joined: Tue Mar 16, 2010 4:06 pm
- Location: San Francisco, California, US
Re: PHP Validation Code...
From what I can tell line 15 appears to be :
Why don't you just provide a relative path to the php file, or a full path if your PHP code is not in the your web directory.
Code: Select all
include 'http://www.dcmedia-design.com/functions.php';
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: PHP Validation Code...
You must use a relative path, or an absolute path from the root, not the online address. If you go to that address, you'll notice that there is no PHP there.
-
Decoughlin
- Forum Newbie
- Posts: 2
- Joined: Thu Nov 04, 2010 1:55 pm
Re: PHP Validation Code...
Yeah I figured it out, but you were right!
What I did was eliminate the calling of another php file and plug the functions.php code right into the main page.
Thanks for the help friends!
What I did was eliminate the calling of another php file and plug the functions.php code right into the main page.
Thanks for the help friends!