Re: Guidance with PHP form to email script

by Gary Krockover <gary(at)garykrockover.com>

 Date:  Thu, 20 Nov 2003 10:44:10 -0600
 To:  hwg-techniques <hwg-techniques(at)hwg.org>
 References:  awebresource
  todo: View Thread, Original
Hi Tenley,

You've already received some good suggestions, I just wanted to add one more.

On the form example that you have below, you have the form submitting to 
the same page it originated from:

<.form method='post' action='<.?=$_SERVER['PHP_SELF']?>'>

Thus the appearance that it "does nothing".  Two options, the first would 
be to obviously have the form post to a landing page that contains the code 
for mailing the form.  To prevent people from abusing this page, or to 
prevent people from accidently going straight to this page and bypassing 
your form, put some error control into it (and I'm not a PHP programmer, 
this is a code example in theory only):

if <referring url> isn't (the url of your form) then redirect them to (url 
of the form)
else submit form

OR

if (key fields from form) are empty then redirect to form
else, submit form

The 2nd option with the form is to keep having it submit to the same page, 
but put in a hidden field telling the page that the form was just submitted 
(again pseudo-code):

<input type="hidden" name="fire_away" value="T">

then, at the top of the page, before the form:

if [fire_away] equals T, then submit form and display {Thank you, your 
information has been sent} and hide the form else,
hide this message, don't submit the form, and display the form

You would do that by wrapping the entire form in the if-then-else statement 
as well as the response message and the form processing code.

Sorry I couldn't be more exact on the code, as I mentioned I'm not a PHP 
programmer (prefer WebDNA myself) but I know the tools are very well in 
place to take care of the above suggestions without much difficulty.

GK

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA