Page 1 of 1

stop forms being sent if blank

Posted: Tue Mar 18, 2008 7:14 pm
by bloodl
Hi all

I have this problem where I receive blank forms. I think its either caused by robots, or maybe people arrive on the wrong page from SE's.

Do you know of any little snippets of code that I can stick inside the php form so that it won't send the email out if the customer's email isn't there or something?

What is the standard protocol for stopping blank emails? I am kind of new to this.

Thanks for any feedback in advance,

Cheers,
Doug

Re: stop forms being sent if blank

Posted: Tue Mar 18, 2008 7:43 pm
by Christopher
Check the form fields to see if they are empty:

Code: Select all

$errors = '';
if (isset($_POST['email']) && $_POST['email']) {
     $email = preg_replace('/[^a-zA-Z0-9\_\-\.\@]/', '', $_POST['email']);
} else {
     $errors .= 'Email required. ';
     $email = '';
}

Re: stop forms being sent if blank

Posted: Wed Mar 19, 2008 1:47 am
by bloodl
thanks for that! Ill give it a whirl