Re: no-resubmit on reload/refresh
| From: | Jørg V . Bryne | Date: | Tue, 06 Mar 2001 13:35:44 +0000 |
| Subject: | Re: no-resubmit on reload/refresh | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-42751@lists.php.net to get a copy of this message | ||
Well, I've had the same problems with an "Send SMS" routine and it caused
the message to get sent twice or more if the user refreshed.
I fixed this by adding the following logic:
If there are post-data, put this into a session variable (an array of
key=>val) and reload the page.
if there are no post-data put the session-variable array into the current
scope again using a foreach loop, and then delete the session variable, so
data won't be processed again. Works like a charm, and doesn't include
javascript. Don't know if it's excactly right for you, so you might have to
modify it a bit.
(From memory only, might be typo's:)
<snip>
<?
session_start();
session_register( pre_posted );
if (count( $HTTP_POST_VARS)>=1) {
foreach( $HTTP_POST_VARS as $k=>$v ) {
$pre_posted[$k] = $v;
}
header( "Location: $PHP_SELF" );
exit;
} elseif ( is_array( $pre_posted )) {
foreach( $pre_posted as $k=>$v ) {
$$k = $v;
}
unset( $pre_posted );
}
echo "<b>You posted: $Test</b><br>Want to refresh?";
?>
<form method=post>
<input name='Test' value='test' size=20>
<input type=submit>
</form>
</snip>
----- Original Message -----
From: "Bruin, Bolke de" <B.deBruin@tijdbeursmedia.nl>
To: "'Jon Haworth'" <JHaworth@witanjardine.co.uk>
Cc: <php-general@lists.php.net>
Sent: Tuesday, March 06, 2001 2:29 PM
Subject: RE: [PHP] no-resubmit on reload/refresh
> That's not really what I want
>
> http://pub.alxnet.com/guestbook?id=2000000
>
> (this one works)
>
> does it without.
>
> On my page I am using a child window to reload the parent window
> , so your solution can't be used unfortunately.
>
> Bolke
>
> -----Oorspronkelijk bericht-----
> Van: Jon Haworth [mailto:JHaworth@witanjardine.co.uk]
> Verzonden: Tuesday, March 06, 2001 2:01 PM
> Aan: Bruin, Bolke de; php-general@lists.php.net
> Onderwerp: RE: [PHP] no-resubmit on reload/refresh
>
>
> Javascript? (I know it's generally horrible, but it's good for this sort
of
> thing)
>
> Stick this in your <head>...</head>:
>
> <script language="JavaScript" type="text/javascript"><!--Begin
> var submitcount=0;
> function jsCheck() {
> if (submitcount == 0) {
> submitcount++;
> return true;
> } else {
> alert("This request has already been submitted, please wait
> while it is processed.");
> return false;
> }
> }
> //End--></script>
>
> And call it from your form like this:
>
> <form name="myform" action="whatever" method="post"
> onSubmit="return
> jsCheck()">
>
> Voila.
>
> HTH
> Jon
>
>
>
> -----Original Message-----
> From: Bruin, Bolke de [mailto:B.deBruin@tijdbeursmedia.nl]
> Sent: 06 March 2001 12:53
> To: php-general@lists.php.net
> Subject: [PHP] no-resubmit on reload/refresh
>
>
>
> I have a form which is submitted by a POST action.
>
> After submitting, the same page (updated though) returns
> with the form. (It's a messageboard)
>
> Now when someone refreshes/reloads the page they get the
> question if they want to resubmit the form.
> I don't want that. You get double posts this way.
>
> I know it is possible to check the input for any duplicates,
> but for example this guestbook
> http://pub.alxnet.com/guestbook?id=120611
>
> (hope the id works) does it differently and your browser does
> NOT if you wnat to resubmit, it just doesn't do it.
>
> Anyone knows how this works (HTTP header maybe?)
>
> cheerz
> Bolke
>
>
> **********************************************************************
> 'The information included in this Email is of a confidential nature and is
> intended only for the addressee. If you are not the intended addressee,
> any disclosure, copying or distribution by you is prohibited and may be
> unlawful. Disclosure to any party other than the addressee, whether
> inadvertent or otherwise is not intended to waive privilege or
> confidentiality'
>
> **********************************************************************
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>