sure you have once experienced this so
anyone who has an insight on how to do this?
thanks.
FORMS: disable re-sending the form contents on page refresh
Moderator: General Moderators
- andyhoneycutt
- Forum Contributor
- Posts: 468
- Joined: Wed Aug 27, 2008 10:02 am
- Location: Idaho Falls
Re: FORMS: disable re-sending the form contents on page refresh
How about some code, or some pseudo-code, or some sort of explanation? 
-
paperplate
- Forum Newbie
- Posts: 16
- Joined: Thu Sep 04, 2008 12:15 pm
Re: FORMS: disable re-sending the form contents on page refresh
I think I know what you mean. User fills out a form, submits it and then refreshes the page...this is a problem only when your form method is "post" though. So the easiest fix is just to use "get" if it's practical. If you stay with "post" you can just redirect them to some other page that isn't a form handler. Example: they fill out form on form.php, method=post,action=form.php. They submit form, and you record the input. Then you display a "entry submitted, click here to continue" or just redirect them to some other page.koguee wrote:sure you have once experienced this so
anyone who has an insight on how to do this?
thanks.
Like andyhoneycutt mentioned, some examples of what you're trying to do will greatly help us & you so that we all can determine a feasible solution.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: FORMS: disable re-sending the form contents on page refresh
The standard practice is to redirect once the form is accepted. Here is example pseudo-code:
Code: Select all
if ($request->isPost() ) {
if ($form->isValid($request) ) {
$model->save($form->getData() );
header('Location: http://mysite.com/form/done/');
exit;
}
} else {
$form->initialize($model->getData() );
}
echo $view->render($form);(#10850)
- andyhoneycutt
- Forum Contributor
- Posts: 468
- Joined: Wed Aug 27, 2008 10:02 am
- Location: Idaho Falls
Re: FORMS: disable re-sending the form contents on page refresh
i completely agree with arborint. If the goal here is to eliminate the possibility of re-submission, redirect the end-user to a page that contains no form or values, or at least none that can modify the previous input. This is a safe route, and more-or-less what I tend to do on my sites as well.
-Andy
-Andy
- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
Re: FORMS: disable re-sending the form contents on page refresh
An alternative option could be to dump the whole of $_POST into a session variable, for example, $_SESSION['previous_post'] and then the next time a $_POST request is submitted, check to make sure it's not identical to the one stored.
I've just come up with that now, so it probably isn't bullet-proof.
I've just come up with that now, so it probably isn't bullet-proof.