Jump to content

Force Users To Type Specific Word In Php Form


beelzebomb

Recommended Posts

I have this nicely working form code for my website, but want to add my own simple captcha.

 

I want to add another field that forces users to type out what they see in a static image that I will insert - so there is only one right answer.

 

If, for example, name required the word 'stan' to be added, how do I force users to do this?

 

Many thanks in advance!

 

<?php
if(isset($_POST['submit'])) {

$name = $_POST['name']; // required
$telephone_number = $_POST['telephonenumber']; // required

if($name=='' ||
$telephone_number=='' )

{

die('You have not filled in all of the required fields - please hit your back button and try again!');

}

else{
$email_to = "my@email.com";
 $email_subject = "Contact from company";
$email_message = "Form details below.\n\n";

function clean_string($string) {
 $bad = array("content-type","bcc:","to:","cc:","href");
 return str_replace($bad,"",$string);
}

$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Telephone Number: ".clean_string($telephone_number)."\n";

// create email headers
$headers = 'From: Company'.
//'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
}
}
?>

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.