Jump to content

PHP Forms - help with form spam please!!


john8m

Recommended Posts

Hi all,

 

I need help with my php forms. I read an article that you can prevent form spam by using a hidden field, and requiring it to be blank for the form to be processed. I have no problems with setting the required html / css up, but have no idea where to start with the php code required to stop the form from being sent if left blank. I have very limited knowledge of php, please bare this in mind.

 

Anyone point me in the right direction or explain the code to me please?

 

I've tried a search on the forum but couldn't find anything, and sites that have mentioned the method never explain what you need to do with the php!

 

Thanks in advance...!

Link to comment
Share on other sites

Hi, I built the site from scratch, its a very simple site - just static html. The only php is for the form.

 

The form just sends an enquiry to an email address.

 

I'm getting lots of spam everyday, and it's all just random text and lots of links to viagra medication etc. It must be automatically generated, it all looks very similar.

 

HERES the php - I adapted this from something I found on the web ages ago.

 

<?php

 

// Handle POST method.

if ($_POST)

{

$name = $_POST['name'];

$email = $_POST['email'];

$phone = $_POST['phone'];

$referrer = $_POST['referrer'];

$messagebody = $_POST['messagebody'];

 

// Compose simple text message:

$message = "

 

------------------------------------------------------------

CONTACT FORM

------------------------------------------------------------

Name: $name

Email: $email

Phone: $phone

Referrer: $referrer

------------------------------------------------------------

\nMessage: $messagebody

------------------------------------------------------------

";

 

 

// Send message to website@example.com

mail("website@example.com", "CONTACT FORM - $name - $email", $message);

 

// Thank the generous user

header("Location:http://www.example.com/thanks.php");

 

 

 

}

else

{

?>

 

 

 

Link to comment
Share on other sites

Here is what I would do, in your Form area, have a sentence that says something like

 

"Hi, please submit the form below for blah blah..etc"

 

Then, create a new input field and have a question that says

 

"What is the third word in the above sentence?"

 

If they don't answer "submit" then don't accept the form.

 

And the good thing is, you can change this validation at will.

Link to comment
Share on other sites

Thanks, but I really want to use the method of a hidden field that should be left blank for usability reasons.

 

What I really want to know is, how do you stop a form from being sent - what is the php code?

 

For example could I use an "if" statement that abandons the process if the "hidden" field is filled in by a spam bot?

 

What would the php be to do this?

 

Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.