You are here:

PHP5/PHP - $robotest function

Advertisement


Question
Hello,

I'm trying to insert a $robotest function in our website. The HTML part works but I'm having issue with the logic on how to write the PHP part.
The coding for our HTML part is the following:
<!-- The following field is for robots only, invisible to humans: -->
        <p class="robotic" id="pot">
         <label>If you're human leave this blank:</label>
         <input name="robotest" type="text" id="robotest" class="robotest" /></p>
<br />
  <input type="submit" name="submit" value="submit" />

Here is what I have for the PHP part so far:
//This part is for the spam
if ($_POST['robotest']) {
         print '<p class="error">You are a gutless robot!</p>;
         $okay = FALSE;
     
      }  

// If there were no errors, print a success message:
if ($okay) {

Answer
Dear Mia,
        I have created the coding for both front-end and back-end, as per your needs (displaying success or failure message and also validation of input fields such as name, email and message). Please don't hesitate to contact me if further assistance needed.

Cheers !

FRONT-END (HTML):
-----------------

<html>
<head>
<title>My form</title>
<style>
.robotic { display: none; }
</style>

<script type="text/javascript">
  function showpot() {
     document.getElementById("pot").className = "";
     return false;
  }
</script>
</head>
<body>

<form method="post" action="back.php">
   <fieldset>
       <legend>Contact Me</legend>
       <p>
         <label>Name:</label>
         <input name="name" type="text" id="name" />
       </p>
       <p>
         <label>E-mail:</label>
         <input name="email" type="text" id="email" />
       </p>
       <p>
         <label>Message:</label>
         <textarea name="message" id="message"></textarea>
       </p>
       <!-- The following field is for robots only, invisible to humans: -->
       <p class="robotic" id="pot">
         <label>If you're human leave this blank:</label>
         <input name="robotest" type="text" id="robotest" class="robotest" />
       </p>
       <p>
         <input type="submit" value="Send Message" class="submit" />
       </p>
   </fieldset>
</form>
Show honey pot field?<br />
</body>
</html>



BACK-END (PHP):
-----------------

<?php

if (!empty($_REQUEST['name']))
{
if (!empty($_REQUEST['email']))
{
 if (!empty($_REQUEST['message']))
 {
 $email=$_REQUEST['email'];
 $message=$_REQUEST['message'];

 # THIS IS A ROBOTEST FUNCTION FOR SPAM PROTECTION

 $robotest = $_POST['robotest'];

    if($robotest)
    {
    $error = "You are a gutless robot.";
    echo $error;
    }
    else
    {
    $success = "You are human";
    echo $success;
    }

 }
 else
 {
 echo "Message Field is Missing";
 }
}
else
{
echo "Email Field is Missing";
}
}
else
{
echo "Name Field is Missing";
}
?>

PHP5

All Answers


Answers by Expert:


Ask Experts

Volunteer


Vimal Abraham

Expertise

I can be able to solve PHP, MySQL and Web Hosting (Linux) related issues that may include cPanel/WHM.

Experience

I have worked under various domains of web development including file sharing, social community, wallpaper management, image hosting, web hosting automation, shopping cart and payment gateway integration. My active portfolios include, http://www.4kwallpapers.in http://www.wallpicz.com

Education/Credentials
I have completed Bachelor of Engineering in Computer Science.

Awards and Honors
Have a Total of nine certificates in Inter and Intra College Competitions that includes technical quiz, program debugging and paper presentation (State Level).

©2016 About.com. All rights reserved.