[PHP] Re: Emtying Variables

2004-07-18 Thread Harlequin
Thanks for the tips guys.

I'll be using session cookies on another site - need to bone up first
though.

I decided to post to a new page, that way the user has to click a link to
back and in doing so the form reloads and refreshes the data without
creating a submission.

Cheap and cheerful...!

-- 
-
 Michael Mason
 Arras People
 www.arraspeople.co.uk
-
Harlequin [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 What's the best way of emptying my variables once my form has done with
them
 because although I disconnect from the database if the user refreshes the
 screen it sends another e-mail to me.

 -- 
 -
  Michael Mason
  Arras People
  www.arraspeople.co.uk
 -

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Emtying Variables

2004-07-18 Thread Skippy
On Sun, 18 Jul 2004 11:29:25 +1000 Trejkaz Xaoza [EMAIL PROTECTED] wrote:
 Php wrote:
  And you can also used a php variable to detect multiple submit:
 
 Even better would be using a token which you give to the user when the form
 is displayed.  That way they can't accidentally submit the form on first
 entry to the site (and believe me, this can happen, because Konqueror
 occasionally remembers a form submission page was in its window the last
 time it was run, and tries to reload the page!)

In order to tackle reload issues, I prefer to use 3 scripts:
A: one to display the form
B: one to receive it through POST and process it (ie. send email)
C: one to display an OK or error message

Of course, depending on situation, two or more of the above can be the same
script behaving differently.

To avoid the reload problem, moving from step B to step C is done via:

header($_SERVER['SERVER_PROTOCOL'].' 303 See Other');
header('Location: C_script_here');

The 303 response forces the browser to use GET for the redirect location.
So no matter how many times the user reloads C they will only get the OK or
error message, no actuall re-processing is performed. And because the
redirect was done via HTTP 3xx code, not JavaScript, if the user uses BACK in
the browser they go directly to A. For all purposes, B is invisible to the
user.


-- 
Skippy - Romanian Web Developers - http://ROWD.ORG

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Emtying Variables

2004-07-17 Thread Torsten Roehr
Harlequin [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 What's the best way of emptying my variables once my form has done with
them
 because although I disconnect from the database if the user refreshes the
 screen it sends another e-mail to me.

Even when you reset all variables on the page (e.g. with $_POST = array())
the user can always refresh and therefore re-submit your form.

To avoid this you could do a redirect after processing the form:

// process form here

header('location: ' . $_SERVER['PHP_SELF']); exit;

Of course then you will have to pass any notices for the user via get (or
store it in a session variable).

Hope this helps.


Regards, Torsten Roehr

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Emtying Variables

2004-07-17 Thread PHP
Harlequin [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 What's the best way of emptying my variables once my form has done with
them
 because although I disconnect from the database if the user refreshes the
 screen it sends another e-mail to me.

 -- 
 -
  Michael Mason
  Arras People
  www.arraspeople.co.uk
 -

Hello,

I don't know if there is really a best way to do this but, some good ways:
- The first step is to avoid multiple submits with the same form when the
user submits severals times. You have to add a small script to avoid this:
script language=JavaScript
var SubmitCount = 0;

function CheckSubmit() {
if (SubmitCount == 0) {
SubmitCount++;
pPost.submit();
 }
else {
// Anti stress alert ;-))
alert(The form has been sent. Please wait take time to drink a
coffee.);
return false;
}
}
/script

form action=myscript.php method=post name=myscript
input type=... your form here...

input name=submit type=button value=Sumit
onClick=CheckSubmit();
/form

- The second step is to avoid the refresh process:
You can use a redirect: header('location: ' . $_SERVER['PHP_SELF']); exit;
And you can also used a php variable to detect multiple submit:
The client side code becomes:
-- mypage.html
script language=JavaScript
var SubmitCount = 0;

function CheckSubmit() {
if (SubmitCount == 0) {
SubmitCount++;
pPost.submit();
 }
else {
// Anti stress alert ;-))
alert(The form has been sent. Please wait);
return false;
}
}
/script

form action=myscript.php method=post name=myscript
input type=hidden value=[[CONTROL]] name=control
...
input type=... your form here...
...
input name=submit type=button value=Sumit
onClick=CheckSubmit();
/form

-- myscript.php
// When you display the page with the form
// Load the form page
$template = new CTemplate(mypage.html);
// Put the control value
$template-assign([[CONTROL]],  . time() . mt_rand());
...

// When you get the form data
// Two cases:
if ($_SESSION['sav_control'] != $_POST['control']) {
// Really the first time: the sav_control variable has not been set
// your code to process the form data

// Keep the control variable
$_SESSION['sav_control'] =  $_POST['control'];

// Display the next page
...
}
else {
// Not the first time: the sav_control variable has been set
// Display the next page
...
}

So, if the user uses the back button, you keep in a session that this form
has already been sent.

Sorry if I use a template style... I think it is a better way to have a good
split between HTML and PHP and it's always easier when you want to explain
something ;-)

Hope this helps... Regards
Patrick

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Emtying Variables

2004-07-17 Thread Trejkaz Xaoza
Php wrote:
 And you can also used a php variable to detect multiple submit:

Even better would be using a token which you give to the user when the form
is displayed.  That way they can't accidentally submit the form on first
entry to the site (and believe me, this can happen, because Konqueror
occasionally remembers a form submission page was in its window the last
time it was run, and tries to reload the page!)

You would generate a random number during the process of displaying the
form, then store that random number into the user's session under that
form's ID.  The number would have to be put into a hidden form field in the
HTML as well.

Then when they submit, you compare the value they send with the value you
have stored in their session.

The frameworks on Java like Struts can automate this.  Perhaps that MVC.PHP
which claims to be a port of Struts can also automate it.

TX


-- 
'Every sufficiently advanced technology is indistinguishable from magic' -
Arthur C Clarke
'Every sufficiently advanced magic is indistinguishable from technology' -
Tom Graves

 Email: Trejkaz Xaoza [EMAIL PROTECTED]
  Web site: http://xaoza.net/trejkaz/
 Jabber ID: [EMAIL PROTECTED]
   GPG Fingerprint: 9EEB 97D7 8F7B 7977 F39F  A62C B8C7 BC8B 037E EA73

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php