PDA

View Full Version : Form Error Msg & I can't figure out why


sweetpea11
07-28-2011, 03:48 PM
My page is here: http://www.swimmasterplus.com/contact.html None of the other pages are up yet, I'm just testing the form at this point. I'm getting an error message for the e-mail and I don't know why. As far as I can tell, everything is correct.

Go ahead & test it out, the responses are coming to me for right now. Could some one please take a peek at the php script & let me know what I did wrong? Thank you.

gentleone
07-28-2011, 03:54 PM
Could some one please take a peek at the php script
We can't have a look because PHP is a server side language... You'll have to post the code from 'send_form_email.php' here in the thread.

Corrosive
07-28-2011, 03:56 PM
We can't view the PHP script online. It gets parsed before it hits the browser. You'll need to post your code here. BTW, you know that half the stuff on that page is overlapping right?

Corrosive
07-28-2011, 03:56 PM
We can't have a look because PHP is a server side language... You'll have to post the code from 'send_form_email.php' here in the thread.

Psyche! 8)

sweetpea11
07-28-2011, 03:56 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body><?php
if(isset($_POST['email'])) {

// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "donna@ispcfinancing.com";
$email_subject = "I'm interested in learning more about SwimMaster Plus";


function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}

// validation expected data exists
if(!isset($_POST['firstName']) ||
!isset($_POST['lastName']) ||
!isset($_POST['email']) ||
!isset($_POST['streetAddress']) ||
!isset($_POST['mailAddress']) ||
!isset($_POST['city']) ||
!isset($_POST['state']) ||
!isset($_POST['zipCode']) ||
!isset($_POST['mainPhone']) ||
!isset($_POST['cellPhone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}

$firstName = $_POST['firstName']; // required
$lastName = $_POST['lastName']; // required
$email_from = $_POST['email']; // required
$email_from = $_POST['streetAddress']; // required
$mainPhone = $_POST['mainPhone']; // not required
$comments = $_POST['comments']; // required

$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$firstName)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$lastName)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";

function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}

$email_message .= "First Name: ".clean_string($firstName)."\n";
$email_message .= "Last Name: ".clean_string($lastName)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "streetAddress: ".clean_string($streetAddress)."\n";
$email_message .= "mainAddress: ".clean_string($mainAddress)."\n";
$email_message .= "city: ".clean_string($city)."\n";
$email_message .= "state: ".clean_string($state)."\n";
$email_message .= "zipCode: ".clean_string($zipCode)."\n";
$email_message .= "mainPhone: ".clean_string($mainPhone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";


// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>


<!-- include your own success html here -->

Thank you for contacting us. We will be in touch with you very soon.

<?php
}
?>
</body>
</html>

sweetpea11
07-28-2011, 04:00 PM
We can't view the PHP script online. It gets parsed before it hits the browser. You'll need to post your code here. BTW, you know that half the stuff on that page is overlapping right?

Yes it's another issue I have to work out. Originally, I had one header image with the logo & it looked great. Now I've been asked to have alternating header images (a different image on each page) and the logo won't stay in the header div. I don't know how to fix it. =) I think it's z-index that layers divs but I don't know for sure... still learning.

sweetpea11
08-08-2011, 03:53 PM
I know I'm not supposed to do this, but I've been waiting a week for help. A simple "We don't know what it is either" would at least let me know something. =)

Corrosive
08-08-2011, 06:16 PM
Many apologies. I totally forgot about you. Sorry!

You have the variable $email_from twice so the second is overwriting the first;

$email_from = $_POST['email']; // required
$email_from = $_POST['streetAddress']; // required

When the second overwrites with a street address it does not pass the 'is this an e-mail address' validation and sends the error message.

sweetpea11
08-08-2011, 06:31 PM
Thank you! It is working now. Sorry to have been a nag, but I've got to get it up & running.

Corrosive
08-08-2011, 06:35 PM
Thank you! It is working now. Sorry to have been a nag, but I've got to get it up & running.

No problem. I have been so snowed under with work recently I've tended to start to answer threads and then get caught up in something else. A 'bump' after a week isn't a crime :wink:

Glad you got it working. It is worth learning for yourself how to debug PHP. A very useful skill if you are getting into some programming.