Posted by Gordon Burditt on 09/18/05 22:05
>I have a contact form that sends an email when the submit button is
>pressed. I have a hidden variable
What kind of variable? HTML form? Javascript? PHP?
>and the code for emailing is only
>executed if the variable is set.
What kind of code? PHP?
>The variable is cleared at the end of
>the code.
Resetting a $_GET or $_POST variable is meaningless after the PHP
code finishes executing. If the page is submitted again, it
gets its new value from the page. Ordinary PHP variables vanish
when the code exits.
I'm not so sure Javascript variables retain their values in this
situation either.
$_SESSION would retain its value if you properly start up a session
at the beginning of the PHP code.
>All works as expected unless the REFRESH button is pressed
>by the user in which case the script is executed and the emails are
>sent once more. Debugging shows the test variable is set again even
>though it was unset before exiting on the previous run. How can this
>be?
>
>I know there are some things I could do like using database entries or
>cookies to hold the variable or even jump to another page which I do
>not want to do.
I doubt cookies would help in this situation, except for their
use in establishing a session.
>There must be a simple explanation and hopefully solution to this.
Database and/or session variables.
Gordon L. Burditt
[Back to original message]
|