Blog | Tutorial

I am not a Robot

I was needing to integrate an `im not a robot` script into my forms and looked at Google`s recptcha functions.

However, I had some difficulty with integration as I wanted to use it in an Ajax environment. Therefore I looked at creating a new solution.

This script is now completed and working fine.

form.php

This code contains the initial tick box to select "I am a Robot" function call. `$aj` is the code required for the ajax event onclick to call the iRobot function. The response returned will be placed in the slot robot_check_id.
$aj = " on click=\"iRobot( `&p=robot_check`, `robot_check_id`);
     return false; \" " ;
print "< span id=\"robot_check_id\" >< input type=\"Checkbox\" name=\"$name\"
    style=\"transform:scale(2); " $aj; required >< /span >I am not a robot " ;

iRobot.php

The purpose of this function is to inject a hidden value onto your form, this will contain a secure secret key which will then be loaded with the form. You can work out this secret code to suit yourself, say based on session and a secure_key that you provide.
$KEY = function_secure_data ( $SESSION, $secure_key) ;
echo "< input type=\"hidden\" name=\"KEY\" value=\"$KEY\" / >";

iRobot.js

This file is the Ajax function call that allows the event to call the php server side function, the response will echo secret data onto your form (to be used in the form submission).
function iRobot(str, name ) { if (str.length==0) { document.getElementById(name).innerHTML=""; document.getElementById(name).style.border="0px"; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4) { if (xmlhttp.status==200) { document.getElementById(name).innerHTML=xmlhttp.responseText; document.getElementById(name).style.border="0px"; } } else document.getElementById(name).innerHTML="< img src=`/images/loading9.gif` alt=`Please wait....` >" ; } xmlhttp.open("GET","/iRobot.php?q="+str,true); xmlhttp.send(); }
I`ll provide a full link to working example shortly.


Please contact me on above link if you have any questions.