Form validates but does not submit any longer. Also, redirect afterwards not working
Some JS is needed, I suspect, to tell it to submit 'if' validation passes. I know my way around code a bit, but I am not a programmer, unfortunately. Can anyone here help?
Also, before, when the submit was working, the page should have re-directed after successful submission to another page (as if a 'thank you' page), but did not. I realize the form apart from the validation, is PHP (and therefore maybe should go in the 'programmer/developer' forum?) but maybe a JS pro can help there too.
The HTML, JS and PHP code for the form as it now stands is as follows:
<form id="PreOrder_Book_2" name="PreOrder_Book_2" method="post" action="">
<input type="text" name="CustomerName" id="CustomerName" />
<input type="text" name="CustomerEmail" id="CustomerEmail" />
<input type="checkbox" name="NotifyPaperback" id="NotifyPaperback" />
Notify me when paperback is available.</p>
<input type="checkbox" name="Notify_eBook" id="Notify_eBook" />
Notify me when eBook is available.</p>
<p>Desired eBook Format:</p>
<input type="radio" name="eBookFormats" value=".mobi" id="eBookFormats_0" />
<input type="radio" name="eBookFormats" value=".epub" id="eBookFormats_1" />
.epub (Nook / Ipad / Sony / Kobo)</label>
<input type="radio" name="eBookFormats" value=".pdf" id="eBookFormats_2" />
.pdf (All readers)</label>
<input type="button" name="button" id="button" value="Submit" onclick="return validateForm();"/>
if (name==null || name=="")
alert("Name cannot be left blank.");
if (z==null || z=="")
alert("Please enter your email.");
//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'];
$message1 = $_POST['NotifyPaperback'];
$message2 = $_POST['Notify_eBook'];
$message3 = $_POST['eBookFormats'];
echo "Name and email are mandatory!";
$email_from = 'firstname.lastname@example.org';//<== 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".
$to = "email@example.com";//<== Put your email address here
$headers = "From: $email_from \r\n";
//Send the email!
//done. redirect to thank-you page.
header('Location: <a href="http://nineinchbride.com'" title="http://nineinchbride.com'" rel="nofollow">http://nineinchbride.com'</a>);
Again, please go easy on me, though I can adapt code a little, I'm no programmer. Thanks for your help.