RE: [PHP] Stopping Forms Being Submitted Twice or Not Complete
| From: | Steve Jackson | Date: | Mon, 28 Apr 2003 12:41:08 +0000 |
| Subject: | RE: [PHP] Stopping Forms Being Submitted Twice or Not Complete | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-145520@lists.php.net to get a copy of this message | ||
You can use PHP to process your form and check that the form fields are
filled in.
I use one function to check form variables and one to check if an email
is possibly valid.
function filled_out($form_vars)
{
// test that each variable has a value
foreach ($form_vars as $key => $value)
{
if (!isset($key) || ($value == ""))
return false;
}
return true;
}
function valid_email($email)
{
// check an email address is possibly valid
if (ereg("^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$",
$email_address))
return true;
else
return false;
}
So in your form processor simply call the functions like:
if (!valid_email($email))
{
// return to the form page with an email error message
}
if (!filled_out($HTTP_POST_VARS))
{
// return to the form page with an error message
}
// otherwise process a thanks page.
You could also check for only essential variables by doing something
like:
if($company&&$firstname&&$secondname&&$email)
{
// process a success page
}
else
{
// process a page which says one of the above variables
hasn't been filled out.
}
Hope this helps.
Steve Jackson
Web Developer
Viola Systems Ltd.
http://www.violasystems.com
stephen.jackson@violasystems.com
Mobile +358 50 343 5159
> -----Original Message-----
> From: Chris Hayes [mailto:chayes@antenna.nl]
> Sent: 28. huhtikuuta 2003 14:40
> To: php-general@lists.php.net; Vicky
> Subject: Re: [PHP] Stopping Forms Being Submitted Twice or
> Not Complete
>
>
> At 13:16 28-4-03, you wrote:
> > > i asked mr Google 'javascript submit form once' and the top
> > > suggestion he gave me looks pretty good:
> > > http://javascript.internet.com/forms/submit-once.html
> >
> >Can you run javascript successfully with PHP then? From past
> experience
> >I assumed they weren't compatible!
>
> You can use them together. You can even exchange variable
> values if you
> know how, though getting it from javascript to PHP requires a
> new page call.
>
> I think your productivity with PHP might improve drasticaly
> when you buy
> (and read) the 2nd edition of the 'PHP Bible' . It explains
> all sorts of
> things that you cannot pick up from trying or reading the PHP
> Manual (which
> is more like a PHP Reference if you ask me).
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>