PDA

View Full Version : Resolved Form validation & Thank you page



TheJoshMan
11-14-2008, 12:40 AM
Ok, I've made a pretty basic contact form that gets emailed to me... However, I can't figure out how to validate it using PHP instead of javascript. I also want to somehow send the user to a "thank you page" after submission. The thank you page will just be a quick "Thanks for submitting your request" or something like that.

Here's a working version:
http://eight7teen.com/DD/formtest/linkad.html


Here's the php script:

<?php
$first = $_POST['fName'];
$last = $_POST['lName'];
$email = $_POST['eMail'];
$url = $_POST['rURL'];
$length = $_POST['howLong'];
$adtype = $_POST['adSelect'];
$desc = $_POST['bDesc'];

$subject = "New Ad Request";


$message = "You've recieved an Ad Request:\n\n\nFirst name: " . $first . "\nLast name: " . $last . "\nEmail: " . $email . "\nRelated URL: " . $url . "\nWhich Ad: " . $adtype . "\nHow Long: " . $length . "\n\nDescription of Site:\n <em>" . $desc . "</em>";


$myemail = "josh@eight7teen.com";

$headers = 'From: adRequest@eight7teen.com' . "\r\n" .
'Reply-To: josh@eight7teen.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

mail($myemail, $subject, $message, $headers);
?>

rangana
11-14-2008, 02:49 AM
$first = $_POST['fName'];
$last = $_POST['lName'];
$email = $_POST['eMail'];
$url = $_POST['rURL'];
$length = $_POST['howLong'];
$adtype = $_POST['adSelect'];
$desc = $_POST['bDesc'];
$flag=true;
$mandate=array($first, $last, $email); // Mandatory fields

if(empty($first))
echo 'I need to know your first name';
elseif(empty($last))
echo 'I need to know your last name';
elseif (empty($email))
echo 'How about your email?';
elseif(!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email))
echo 'Please check your email. It\'s invalid.';
else if(!isset($url))
echo 'Please let me know the url';


else
{
$message = "You've recieved an Ad Request:\n\n\nFirst name: " . $first . "\nLast name: " . $last . "\nEmail: " . $email . "\nRelated URL: " . $url . "\nWhich Ad: " . $adtype . "\nHow Long: " . $length . "\n\nDescription of Site:\n <em>" . $desc . "</em>";


$myemail = "josh@eight7teen.com";

$headers = 'From: adRequest@eight7teen.com' . "\r\n" .
'Reply-To: josh@eight7teen.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

echo '<h1>Thank You! Email sent</h1>';
mail($myemail, $subject, $message, $headers);
}

TheJoshMan
11-14-2008, 04:03 AM
that looks simple enough, but it gives me a parsing error.

here's the link: http://eight7teen.com/DD/formtest/linkad.html


Parse error: syntax error, unexpected $end in /mnt/w0503/d26/s30/b02d3b61/www/eight7teen.com/DD/formtest/sendit.php on line 37

rangana
11-14-2008, 04:12 AM
It's working fine at my end when tested I guess you'll receive an email at your end.

Please ensure that the brackets have a matching closing for opening and vice versa.

TheJoshMan
11-14-2008, 04:23 AM
that's what it was, I guess I missed a curly bracket on the last else statement.

Thanks a million man!