The default web form will look like this: For simplicity it asks for four pieces of information from the user: name, phone, age and the captcha input using Recaptcha. The explanation and process is basically similar to the previous However, since we are using Recaptcha, we will revise the old captcha from: <img src="/ajaxwebform/captcha.php" /> <br /> Enter the Captcha as shown above: <br /> <br /> <input style="background-color: #FFFFC0" type="text" name="captcha" id="captcha" size="10"> <br /> <br /> Into this script: <?php require_once('recaptchalib.php'); $publickey = "***Your own website recaptcha public key here***"; echo recaptcha_get_html($publickey); ?> The PHP recaptcha script to be added takes care of displaying the captcha image to the user. Since you are using PHP scripts, it is important that the file name extension uses .php rather than .htm or something else. You will need to add your own recaptcha public key and change the value of the $publickey variable: $publickey = "4Ld1R3434343KJKJKJMGylVnGFGFGFz1R8NraDDDDDQW"; Finally, in the AJAX JavaScript code, you will also be sending the Recaptcha parameters via <script type="text/javascript"> function sendRequest() { new Ajax.Request("/ajaxwebform/ajaxvalidate.php", { method: 'post', parameters: 'name='+$F('name')+'&phonenumber='+$F('phonenumber')+'&age='+$F('age')+'&captcha='+$F('captcha'), onComplete: showResponse }); } function showResponse(req){ $('show').innerHTML= req.responseText; } </script> Into this: <script type="text/javascript"> function sendRequest() { new Ajax.Request("/ajaxrecaptcha/ajaxvalidate.php", { method: 'post', parameters: 'name='+$F('name')+'&phonenumber='+$F('phonenumber')+'&age='+$F('age')+'&recaptcha_challenge_field='+$F('recaptcha_challenge_field')+'&recaptcha_response_field='+$F('recaptcha_response_field'), onComplete: showResponse }); } function showResponse(req){ $('show').innerHTML= req.responseText; } </script>
Recaptcha variables are passed in the above ... +'&recaptcha_challenge_field='+$F('recaptcha_challenge_field')+'&recaptcha_response_field='+$F('recaptcha_response_field'),
These variables are recaptcha_challenge_field and recaptcha_response_field. Those are the only changes made to the original
|
|
|
|
|
|
|
|