As the question stated, how do I retrieve the form values from the previous page.
Basically I'm creating a form wizard
1. enter the form inputs -> next step 2. confirmation and get all the value开发者_如何学PythonsI can use $_GET
to get those values from the URL address, but for the form validation I'm using jquery ajax. Do I need to create a session variable for each text input value?
Save the values in $_SESSION
and retrieve them on the next page:
// On the first page....
session_start();
// Process your code...
$_SESSION['val1'] = $_POST['val1']; // don't forget your validation
$_SESSION['val2'] = $_POST['val2'];
// Display the next part of your form...
// On the second page
session_start();
// Retrieve your values
$val1 = $_SESSION['val1'];
$val2 = $_SESSION['val2'];
// Retrieve values from the second part of your form
something($_POST['val3']);
something($_POST['val4']);
yes, you have to use session to preserve data between HTTP requests.
Another way: you can create multi pages using js and displaying next one when validation for curr page is complete. There's lot of jQuery plugins to do that.
You can also store a serialized json object that contains all the form data inside a cookie.
After validating the form you can send another ajax request. Your data will then be available in $_GET.
精彩评论