I thought it would be easy (silly, I know) and so I followed the instructions I found at this site for a PHP email form: http://www.html-form-guide.com/email-form/dreamweaver-email-form.html I didn't need help with the Dreamweaver interface at all, I just needed the script, and I knew (or thought I knew) how to adapt their simple form into the form I needed, and adapt the script accordingly.
The form in question may be found at this URL: http://nineinchbride.com/SuitedForWar_BookTwo_PreOrderForm.php
The code as it presently exists on the page is as follows:
<form id="PreOrder_Book_2" name="PreOrder_Book_2" method="post" action="">
<p>Your Name:
<input type="text" name="CustomerName" id="CustomerName" />
</p>
<p>Your Email:
<input type="text" name="CustomerEmail" id="CustomerEmail" />
</p>
<p>
<input type="checkbox" name="NotifyPaperback" id="NotifyPaperback" />
Notify me when paperback is available.</p>
<p>
<input type="checkbox" name="Notify_eBook" id="Notify_eBook" />
Notify me when eBook is available.</p>
<p>Desired eBook Format:</p>
<p>
<label>
<input type="radio" name="eBookFormats" value=".mobi" id="eBookFormats_0" />
.mobi (Kindle)</label>
<br />
<label>
<input type="radio" name="eBookFormats" value=".epub" id="eBookFormats_1" />
.epub (Nook / Ipad / Sony / Kobo)</label>
<br />
<label>
<input type="radio" name="eBookFormats" value=".pdf" id="eBookFormats_2" />
.pdf (All readers)</label>
</p>
<p>
<input type="submit" name="button" id="button" value="Submit" />
<br />
</p>
</form><script>
function validateForm()
{
var name=document.forms["PreOrder_Book_2"]["CustomerName"].value;
if (name==null || name=="")
{
alert("Name cannot be left blank.");
return false;
}
var z=document.forms["PreOrder_Book_2"]["CustomerEmail"].value;
if (z==null || z=="")
{
alert("Please enter your email.");
return false;
}
}
</script>
<script><?php
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
}
$name = $_POST['CustomerName'];
$visitor_email = $_POST['CustomerEmail'];
$message = $_POST['NotifyPaperback'];
$message = $_POST['Notify_eBook'];
$message = $_POST['eBookFormats'];
//Validate first
if(empty($name)||empty($visitor_email))
{
echo "Name and email are mandatory!";
exit;
}
$email_from = 'webmanager@nineinchbride.com';//<== Put your email address here
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n".
"email address: $visitor_email\n".
"Here is the message:\n $message".
$to = "webmanager@nineinchbride.com";//<== Put your email address here
$headers = "From: $email_from \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: http://nineinchbride.com');
?></script>
Please bear in mind that while I know my way around code a bit (enough to adapt things a little, adjust naming for consistency and the like), I am not a programmer per se, so please go easy on me.
Update 1:
Okay, I'm making progress here. I made the following changes to the PHP:
$name = $_POST['CustomerName'];
$visitor_email = $_POST['CustomerEmail'];
$message1 = $_POST['NotifyPaperback'];
$message2 = $_POST['Notify_eBook'];
$message3 = $_POST['eBookFormats'];
//Validate first
if(empty($name)||empty($visitor_email))
{
echo "Name and email are mandatory!";
exit;
}
$email_from = 'webmanager@nineinchbride.com';//<== Put your email address here
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n".
"email address: $visitor_email\n".
"Notify When Paperback Is Available: $message1\n".
"Notify When eBook Is Available: $message2\n".
"My eBook Format Is: $message3\n".
And, hurray, I'm getting all the form data. Figured it out for myself too ;-)
However, none of the validation is working. And the re-direct after successful submission is not working either. Any idea what's up with that?
Update 2:
Wow, validation problem solved, thank you Poria! I just added
<input type="button" name="button" id="button" value="Submit" onclick="return validateForm();"/>
to the form itself in place of the submit button I had before, and now the front end validation is working. Great!
But now the form itself does not submit any longer! What did I do wrong?