Reputation: 6116
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.
Upvotes: 0
Views: 534
Reputation: 21856
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.
Upvotes: 1