Form validates but does not submit any longer. Also, redirect afterwards not working

They have: 1 posts

Joined: May 2016

Now that I have the javascript validation on this form working, the form itself is no longer submitting (it was working just fine before I changed the form's submit button to

see, http://nineinchbride.com/SuitedForWar_BookTwo_PreOrderForm.php

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="">
              <p>Your Name:
                <input type="text" name="CustomerName" id="CustomerName" />
              </p>
              <p>Your Email:&nbsp;
                <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="button" name="button" id="button" value="Submit" onclick="return validateForm();"/>
                <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>"

<?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'];
   
$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 = '[email protected]';//<== 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 protected]";//<== 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: <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.

He has: 2 posts

Joined: Apr 2016

Its best you can go with java with css to make it easy and simple.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.