Forum Moderators: coopster
I'm trying to send some data between two scripts... well the same script, refreshed. Basically, the situation is this - the user is presented with some form inputs which contain preset values from the local db, which the user can override at his or her convenience. Obviously when s/he submits, their changes are available in the $_POST array. The same script that creates the form inputs also evaluates them after submission.
If there are errors in the input, the script refreshes with an error message. The problem is, the changes the user has made to the form inputs have been overriden with the original values from the database, and the $_POST array which contains their changes is no longer available. However, it is much easier for the user if his or changes are still there and s/he can simply amend the faulty entry, rather than rewrite all of the changes all over again.
So my question is, is there a way to somehow preserve the $_POST array for use in the refreshed page (preferably without adding text to the address string a la $_GET)?
Thanks
Something like:
if ($_POST["somevar"])
{
$somevar_default = $_POST["somevar"];
}
else
{
$somevar_default = get_somevar_from_database();
}print "<input type='text' name='somevar' value='".$somevar_default."'>";
Failing that, perhaps the data temporarily be stored in the $_SESSION array - is that possible?
Thanks
I'm not sure exactly what you mean by refreshing. You say "refreshing because of the error"; but in a standard PHP form handling script there is no need to "refresh" anything because of invalid input; just continue on and output the form again - complete with saved values from the original input.
Can you post a small snippet of your code so we can see what you're doing...
I've changed it now so there's no refresh and hence the $_POST array is still available; the error is stored in the $_SESSION array instead.