PHP Form Builder Class / Examples / Captcha

Version: Released:

Captcha - This project leverages reCAPTCHA's anti-bot service to provide captcha functionality. For more information about this service, visit http://www.google.com/recaptcha. Below you will find a detailed list of the various form attributes that affect the reCAPTCHA integration.

When using the addCaptcha function in your forms, there are a few important things to keep in mind. First, it's essential that you invoke the validate function after the form's data has been submitted. If you fail to do this, the user's reCAPTCHA solution will never be validated. If you have questions regarding how to use the validate function, you can view this example file's php source code. The second important thing to keep in mind is that reCAPTCHA only permits one challenge phrase per page. So, this means that you can only use the addCaptcha function once per webpage. Finally, you can use the javascript function Recaptcha.reload() to force a new reCAPTCHA challenge phrase to be displayed to the user. This can be helpful if you're using the "ajax" form attribute to submit the form's data via AJAX.

Processing

<?php
$form 
= new form("captcha_0");
$form->setAttributes(array(
    
"width" => 400
));

if(!empty(
$_GET["errormsg_0"]))
    
$form->errorMsg filter_var(stripslashes($_GET["errormsg_0"]), FILTER_SANITIZE_SPECIAL_CHARS);

$form->addHidden("cmd""submit_0");
$form->addCaptcha("Captcha:");
$form->addButton();
$form->render();
?>