Hi,
I have a form with $POST. When the user fills out the form, he is sent to a new page check.php. On this new page, I connect to a database and check if $POST[title] exists in the database. If it does, I redirect the user back to the form and send an error message like "This title already exists. Please choose another title." All is well, except I don't know how to resend the $_POST variables back to populate the form, so the user will not have to retype the data that was already typed in.
Thank you.
Mike
On the page where you validate the data, populate $SESSION with the $POST data. Then when you pass the client back to the form, you can check if $_SESSION has any stored values and , if so, use them to re-populate the form.
How do I populate $SESSION with the $POST data?
Thanks very much.
Various ways. You could simply do:
$_SESSION['formdata'] = $_POST;
$SESSION['formdata'] would then be an array Or,
foreach ($_POST as $key=>$value) { $_SESSION[$key] = $value; }
That way $_SESSION['name'] would contain $_POST['name'] etc.
I would like to use the first method. But when back on the page with the form, how would access $SESSION['formdata']? Or more specifically, how would I reset each $POST variable?
Is it possible at all to set $POST variables? Like: $POST['title'] = "This is a title";
Thanks.
Also, do I have to turn on something like register_session_vars?