|
Posted by "Satyam" on 11/26/65 11:16
"Marek Kilimajer" <lists@kilimajer.net> wrote in message
news:428A7034.5010607@kilimajer.net...
> Robert Meyer wrote:
>> Hello,
>>
>> Scenario:
>> 1) User is presented a blank form.
>> 2) User fills in form.
>> 3) User submits form.
>> 4) Record is added to database.
>> 5) Back to 1).
>
> Go really back to 1) - use redirect. After the record is added to the
> database, use something like:
> header('Location: http://yourserver.com/form.php');
> exit;
>
Or, in general, redirect to any page as soon as you made the insert. It can
be back to the begining or to a confirmation page, so the user gets a
feedback of what has just been done. The point is, don't show the
confirmation or the new input form right in the same page as you did the
insert, redirect to it in some way.
I use to process my data in a single form per operation. I make each page
like this:
if ($_REQUEST['confirm'] == 'true') {
// show the confirmation of the last operation
}
if ($_REQUEST['submit'] == 'Save') {
// do the insert here
header('Location: http://yourserver.com/form.php?confirm=true');
}
// here, show the input form which will show either for the first time or
after the confirmation
// which ends with:
<input type=submit name=submit value=Save />
</form>
You might add to the redirect header some more arguments to be more explicit
about what is it that you are confirming. Anyway, the point is that the
browser will store the redirected-to address with all its arguments, not the
one with the form data, so, a refresh will give you the confirmation page,
not the insert one.
Satyam
>> All is fine to here.
>> 6) User clicks refresh.
>> 7) Another record is added, same data except auto-increment field.
>> How do I prevent these last two steps, or at least prevent a record
>> from being added when refresh is clicked?
>
> You should see a message from your browser that data is being reposted.
Navigation:
[Reply to this message]
|