Jump to content

Contact Form tweaks


Chrisj

Recommended Posts

Someone had helped me set up a basic Contact Form that simply sends the info to an email address upon submission, and helped  add the functionality of a CAPTCHA, and a function to Agree To Terms.

Well, instead of Captcha, a simple question is posed in the Form: Is Fire Hot or Cold?

 

Anyway, I plugged in the suggested lines of code into the html form, and the accompanying very simple php handler (below).

 

After answering the question (wrong), the user exits to a blank page that simply says "wrong answer". I'd like to have the words "Wrong Answer" appear on the Contact Form page, instead of exiting.

 

And I'd like to add a link to the Agree To Terms, so the user can read the terms they are agreeing to, and also not allow a user to submit/proceed until he agrees.

 

I'm sure these are very simple tweaks. Please let me know if you're interested in helping me "have the words "Wrong Answer" appear on the Contact Form page, instead of exiting" and "add a link to the Agree To Terms, so the user can read the terms they are agreeing to, etc.".

 

Thanks

 

<?php
$mailto		= 'email@email.com';
$mailsubj	= "Contact Form submission";
$mailhead	= "From:CForm\n";
$mailbody 	= "--- Contact form results ---\n";

foreach($_REQUEST as $key => $value)
{
if($key != 'PHPSESSID')
	{
	$mailbody .= $key.": ".$value."\n";
	}
}
if(isset($_POST['ans']) && $_POST['ans']!='hot') exit('Wrong answer');

if(empty($_POST['agree']) || $_POST['agree'] != 'agree')
{
echo "If you agree with the terms, check the Agree check box";
exit;
}

$mailbody .= date('Y-m-d H:i:s',strtotime("now"));
mail($mailto, $mailsubj, $mailbody, $mailhead);
echo "<h2>Thanks!</h2>"
//print_r($_REQUEST);
?>

Link to comment
Share on other sites

If your question is always "Is Fire Hot or Cold" then by-passing this 'anti-spamming' system if you so call it won't be very hard.  If you would like to have the errors display on top of the contact form, you will need to leave the form's action to empty, to it sends the HTTP POST vars to itself.

 

example

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

    $answer = trim(strtolower($_POST['answer']));

     if(empty($username)){

          print  "Please enter your username";

     }elseif($answer != "hot"){

         print "Wrong Answer!";

     }else{
      
         header("location:somepage.php");   
         exit();

    } 


}
?>
<form method="Post" action="">
     <input type="text" name="answer" id="answer" />
     <input type="Submit" name="Submit" value="Submit" />
</form>

 

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.