0

I have a 3 page registration site. When the user selects one of three options on the first page they can submit and move onto the 2nd page. There they fill out information and click submit which should take them to the third page. The problem is the jquery redirect code after clicking submit on the 1st and 2nd page is NOT working. This is the code in the first page:

<?php
session_start();
$errors = false;
$message="";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    if (!isset($_POST['Reg_type']) || !preg_match('/^[123]$/', $_POST['Reg_type'])) {
        $message = "Please select an option";
        $errors = true;
    }
    if (!$errors) {
        $_SESSION["regtype"]=$_POST["Reg_type"];
        header("Location: Registration_2.php");
        exit;
    }
}
?>
<div id="form_page1">
<form id="frmtype1" name="frmtype1" method="post">
<input type="radio" name="Reg_type" value="1"/> option1 <br/>
<input type="radio" name="Reg_type" value="2"/> option2 <br/>
<input type="radio" name="Reg_type" value="3"/> option3 <br/>
<input type="submit" name="Submit" value="Submit" />
<?php
if($errors)
echo $message;
?>

I'm trying to convert that php code into javascript and this is what I have:

<script>
$(document).ready(function(e) {
    $("form").submit(function() {
        var data= $(this).serialize();
        alert(data);
        $.post("/Registration_1.php",$("#form_page1").serialize());
            window.location.replace("http://www.google.com"); //just for testing purposes
    });
});
</script>

But for some reason the jquery stuff just WON'T work, so i have to use the php instead. Can anyone tell me what the problem is? Does the first argument of the post method have to be the page you want to go to (Registration_2.php) or the page you are asking data from? Hopefully if the first page's jquery code is fixed it can fix the 2nd page. I've been working/researching this problem for the past 3 hours to no avail. Please help, thank you.

2
  • you did not have any closing form html tag Commented Sep 13, 2012 at 16:49
  • @rsz I didn't copy all the code Commented Sep 13, 2012 at 16:52

1 Answer 1

1

Why choose such a complicated solution?

Form 1:

<form action="form2.php"  method="post">
  <input type="submit" >
</form>

Form 2:

<form action="form3.php"  method="post">
  <input type="submit"> 
</form>

etc. etc.

Sign up to request clarification or add additional context in comments.

4 Comments

I should have put this in the post but I already know of this and I am not doing that for specific reason. I was having an extremely hard time validating the form with an action attribute set.
There is no difference in validating a post from and a serialize from ajax submit. ajax is harder because of the deserialization!
But if I put action="page2.php" how do I force it to validate first before deciding whether to go to the next page or stay on this page?
Do your checks, and then use a header('Location: pageX.php') to move to another page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.