stop forms being sent if blank

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bloodl
Forum Commoner
Posts: 48
Joined: Thu Jun 21, 2007 12:33 am

stop forms being sent if blank

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: stop forms being sent if blank

Post 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 = '';
}
(#10850)
bloodl
Forum Commoner
Posts: 48
Joined: Thu Jun 21, 2007 12:33 am

Re: stop forms being sent if blank

Post by bloodl »

thanks for that! Ill give it a whirl
Post Reply