forms - how to structure server side script with php
I am trying to start an online service. Users fill out a form submit it then go to another page. On the 2nd page they choose a service. From that page they go to a 3rd page. I would like to do this in 3 pages as to encourage users to finish the sequence (they are already invested time-wise by 2nd page).
How could I better send data from page 1 to page 3? So far I was just going to send data from page 1 to a server side php script, send that data to page 2 then repeat the process until page 3. Is there a more proper way to accomplish this?
my code for the form submit is
<?php
$varRedirect = "order.php";
if(isset($_POST["submit"]) )
{
$var1 = $_POST["element_1"];
$var2 = $_POST["element_1"];
$var3 = $_POST["element_1"];
$var4 = $_POST["element_1"];
$var5 = $_POST["element_1"];
$var6 = $_POST["element_1"];
$var7 = $_POST["element_1"];
$var8 = $_POST["element_1"];
$var9 = $_POST["element_1"];
}
/* begin switch logic */
redirect($varRedirect."?var1=".$var1."&var2=".$var2."&var3=".$var3."&var4=".$var4."&var5=".$var5."&var6=".$var6."&var7=".$var7."&var8=".$var8."&var9=".$var9);
/* functions */
function redirect($url, $statusCode = 303)
{
header('location: ' .$url, true, $statusCode);
die();
}
?>
Answer
Solution:
if you prefer redirect, you can simplify the process by using
http_build_query
not checked well, but you can see the idea.
Answer
Solution:
Recommend using session. There you can store data for a user through pages. http://php.net/manual/en/features.sessions.php
Answer
Solution:
Wow! Don't use get so send forms unless this is an search form! Send data with POST between pages!
Now you have few solutions:
?some_id=332
appended to the url and every next form submitting save data to database using?some_id=332
. In such way you don't need to pass data between forms. You can get it always form the database by?some_id=332
. Moreover, in such way user can to do refreshes, next/prev editing. You just need to check if?some_id=332
is provided in the url, and if yes - load the data to form from database.