PDA

View Full Version : I Cant Get The Form To Show Users Email! Can You Help!


mydogisthebest
19th June 2010, 16:55
Hi - I am having a problem with some Php in relation to form validation/output.

I have been messing with the following coding for a while now and the thing that is bugging me, is the fact that no matter what I do I can't get the email (users email address) to show in the form results/output. I did have it at one point, but alas lost it somewhere along the way.

I know that it will be something silly, but in the end two heads are better than one.

As always, thanks.


<?php
/* Set e-mail recipient */
$myemail = "myemail@sample.net (myemail@sample.net)";
/* Check all form inputs using check_input function */

$firstname = check_input($_POST['FirstName'], "First Name");
$lastname = check_input($_POST['LastName'], "Last Name");
$address = check_input($_POST['Address']);
$postcode = check_input($_POST['Postcode']);
$telephone = check_input($_POST['Telephone']);
$email = check_input($_POST['Email']);

/* If email is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
{
$email = '';
}
/* Let's prepare the message for the e-mail */
$message = "Thank You -
Your order form has been submitted by:
First Name: $firstname
Last Name: $lastname
Telephone: $telephone
Email: $email
Address: $address
Postcode: $postcode
End of message
";
/* Send the message using mail() function */
mail($myemail, $subject, $message);
/* Redirect visitor to the thank you page */
header('Location: http://www.paypal.com');
exit();
/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
<html>
<body>
<b>Please correct the following error:</b><br />
<?php echo $myError; ?>
</body>
</html>
<?php
exit();
}
?>

dots and spots Jeff
19th June 2010, 19:41
Hi - I am having a problem with some Php in relation to form validation/output.

I have been messing with the following coding for a while now and the thing that is bugging me, is the fact that no matter what I do I can't get the email (users email address) to show in the form results/output. I did have it at one point, but alas lost it somewhere along the way.

I know that it will be something silly, but in the end two heads are better than one.

As always, thanks.


<?php
/* Set e-mail recipient */
$myemail = "myemail@sample.net (myemail@sample.net)";
/* Check all form inputs using check_input function */

$firstname = check_input($_POST['FirstName'], "First Name");
$lastname = check_input($_POST['LastName'], "Last Name");
$address = check_input($_POST['Address']);
$postcode = check_input($_POST['Postcode']);
$telephone = check_input($_POST['Telephone']);
$email = check_input($_POST['Email']);

/* If email is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
{
$email = '';
}
/* Let's prepare the message for the e-mail */
$message = "Thank You -
Your order form has been submitted by:
First Name: $firstname
Last Name: $lastname
Telephone: $telephone
Email: $email
Address: $address
Postcode: $postcode
End of message
";
/* Send the message using mail() function */
mail($myemail, $subject, $message);
/* Redirect visitor to the thank you page */
header('Location: http://www.paypal.com' (http://www.paypal.com%27));
exit();
/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
<html>
<body>
<b>Please correct the following error:</b><br />
<?php echo $myError; ?>
</body>
</html>
<?php
exit();
}
?>


I think your error may be what I've highlighetd in red

/* If email is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
{
$email = '';
}


The code above ^^ appears to be setting the $email variable to "

Try removing that line of code?

Jeff

mydogisthebest
19th June 2010, 20:08
I think your error may be what I've highlighetd in red

/* If email is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
{
$email = '';
}


The code above ^^ appears to be setting the $email variable to "

Try removing that line of code?

Jeff

dots and spots Jeff - .oOo.oOo. yOU aRe A STar .oOo.oOo.

I couldn't see the woods for the trees.

:):):):):):)

dots and spots Jeff
19th June 2010, 20:39
No problem - happy to help!

Jeff