How is your php structured???
By that I mean the order in which your script processes.
Last should be first and first should be last.
Hopefully that makes sense. If it doesn't, here's what I mean. Lets say the stages in the process are:
A) Collect Data via form
😎 Present data and ask for confirmation
C) Store data and reset to beginning.
Hopefully, thats along the lines of what you want to achieve.
So here's how I'd structure my script:
if ($action == "confirm") {
// Do data storing
unset($vars); //repeat for all passed variables
unset($action);
echo "confirmation message to screen";
};
if ($action == "preview") {
// Preview data
echo $vars;
unset($action);
};
echo "form to complete with field values using value=\"$var\"";
The first thing this script is going to do is check whether the value of $action is "confirm" (the final stage of our app). If it is, its going to manipulate the data and create the db record. Then its going to discard the variables passed to it ( using unset($var) ) where $var is the name of YOUR variable. Repeat for each passed variable. Finally, its going to unset($action)
Now when the script meets if ($action == "confirm") , if the form has already been confirmed and submitted second time round, then the variable $action will have been discarded. Therefore this portion of the script will be skipped. If the variable $action exists, then the form hasn't been processed by the final stage but it does need previewing. So, the second stage of the script simply previews the script. However, it does not discard the variable values .
The final commands create the form. In this simple example, the form will always be visible. BUT if the script is callled first time, the variables we tell our form to use for value="" will not exist, so the form is empty. If the script is on preview stage, the variables are as previously passed and intact, therefore they appear in the input fields. If the form has been confirmed, the variables have been processed into the database and subsequently discarded and as such, the form once again, will appear empty.