Package: Controls

Class: Zebra_Form_Captcha

source file: /includes/Captcha.php

Class Overview

XSS_Clean
|
--Zebra_Form_Control
|
--Zebra_Form_Captcha

Class for CAPTCHA controls.

Author(s):

Copyright:

  • (c) 2006 - 2016 Stefan Gabos

Methods

Inherited methods

Class: Zebra_Form_Control

Zebra_Form_Control::change_case()
Call this method to instruct the script to force all letters typed by the user, to either uppercase or lowercase, in real-time.
Zebra_Form_Control::disable_spam_filter()
Disables the SPAM filter for the control.
Zebra_Form_Control::disable_xss_filters()
Disables XSS filtering of the control's submitted value.
Zebra_Form_Control::get_attributes()
Returns the values of requested attributes.
Zebra_Form_Control::lock()
Locks the control's value. A locked control will preserve its default value after the form is submitted even if the user altered it.
Zebra_Form_Control::reset()
Resets the control's submitted value (empties text fields, unchecks radio buttons/checkboxes, etc).
Zebra_Form_Control::set_attributes()
Sets one or more of the control's attributes.
Zebra_Form_Control::set_rule()
Sets a single or an array of validation rules for the control.
Zebra_Form_Control::_render_attributes()
Converts the array with control's attributes to valid HTML markup interpreted by the toHTML() method

Class: XSS_Clean

XSS_Clean::sanitize()
Sanitizes submitted data so that Cross Site Scripting Hacks can be prevented.

Class methods

constructor __construct()

void __construct ( string $id , string $attach_to , [ $storage = 'cookie'] )

Adds a CAPTCHA image to the form.

Do not instantiate this class directly! Use the add() method instead!

You must also place a textbox control on the form and set the "captcha" rule to it! (through set_rule())

Properties of the CAPTCHA image can be altered by editing the file includes/captcha.php.

By default, captcha values are triple md5 hashed and stored in cookies, and when the user enters the captcha value the value is also triple md5 hashed and the two values are then compared. Sometimes, your users may have a very restrictive cookie policy and so cookies will not be set, and therefore they will never be able to get past the CAPTCHA control. If it's the case, call the captcha_storage method and set the storage method to "session".

  1. // create a new form
  2. $form new Zebra_Form('my_form');
  3.  
  4. // add a CAPTCHA image
  5. $form->add('captcha''my_captcha''my_text');
  6.  
  7. // add a label for the textbox
  8. $form->add('label''label_my_text''my_text''Are you human?');
  9.  
  10. // add a CAPTCHA to the form
  11. $obj $form->add('text''my_text');
  12.  
  13. // set the "captcha" rule to the textbox
  14. $obj->set_rule(array(
  15.     'captcha' => array('error''Characters not entered correctly!')
  16. ));
  17.  
  18. // don't forget to always call this method before rendering the form
  19. if ($form->validate()) {
  20.     // put code here
  21. }
  22.  
  23. // output the form using an automatically generated template
  24. $form->render();
Parameters:
string $id

Unique name to identify the control in the form.

This is the name of the variable to be used in the template file, containing the generated HTML for the control.

  1. // in a template file, in order to print the generated HTML
  2. // for a control named "my_captcha", one would use:
  3. echo $my_captcha;
string $attach_to The id attribute of the textbox control to attach the CAPTCHA image to.
$storage
Top

method toHTML()

string toHTML ( )

Generates the control's HTML code.

This method is automatically called by the render() method!

Tags:
return: The control's HTML code
Top