HTML_QuickForm2_Captcha
[ class tree: HTML_QuickForm2_Captcha ] [ index: HTML_QuickForm2_Captcha ] [ all elements ]

Class: HTML_QuickForm2_Element_Captcha

Source Location: /HTML_QuickForm2_Captcha-0.1.2/HTML/QuickForm2/Element/Captcha.php

Class Overview

HTML_QuickForm2_Element_Input
   |
   --HTML_QuickForm2_Element_Captcha

Base class for captcha elements for HTML_QuickForm2: Completely Automated Public Turing test to tell Computers and Humans Apart.


Author(s):

Version:

  • Release: 0.1.2

Variables

Methods


Child classes:

HTML_QuickForm2_Element_Captcha_ReCaptcha
Captcha element utilizing the ReCaptcha service.
HTML_QuickForm2_Element_Captcha_Numeral
Numeral captcha element for HTML_QuickForm2.
HTML_QuickForm2_Element_Captcha_TextCAPTCHA
Quickform2 captcha element that uses the Text_CAPTCHA package as captcha generator.

Inherited Variables

Inherited Methods


Class Details

[line 44]
Base class for captcha elements for HTML_QuickForm2: Completely Automated Public Turing test to tell Computers and Humans Apart.

Used as anti-spam measure.

Features:

  • Multiple forms on the same page may have captcha elements with the same name
  • Once a captcha in a form is solved, it stays that way until the form is valid. No need to re-solve a captcha because you forgot a required field!
  • Customizable status messages i.e. when captcha is solved
When the form is valid and accepted, use clearCaptchaSession() to destroy the captcha question and answer. Otherwise the form catpcha is seen as already solved for the user.



[ Top ]


Class Variables

$attributes = array(
        'size' => 5,
        'type' => 'text'
    )

[line 60]

Array of input element attributes, with some predefined values
  • Access: protected

Type:   array


[ Top ]

$capGenerated =  false

[line 70]

If the captcha has been generated and initialized already

Type:   boolean


[ Top ]

$session =  null

[line 77]

Session object to store captcha data and solutions in.
  • Access: protected



[ Top ]

$sessionPrefix =  '_qf2_captcha_'

[line 53]

Prefix for session variable used to store captcha settings in.
  • Access: protected

Type:   string


[ Top ]



Method Detail

__construct (Constructor)   [line 95]

HTML_QuickForm2_Element_Captcha __construct( [string $name = null], [mixed $attributes = null], [array $data = array()])

Create new instance.

Captcha-specific data attributes:

  • captchaSolved - Text to show when the Captcha has been solved
  • captchaSolutionWrong - Error message to show when the captcha solution entered by the user is wrong
  • captchaRender - Boolean to determine if the captcha itself is to be rendered with the solution input element

  • Access: public

Overridden in child classes as:

HTML_QuickForm2_Element_Captcha_TextCAPTCHA::__construct()
Constructor. Set adapter specific data attributes.
HTML_QuickForm2_Element_Captcha_Image::__construct()
Set adapter specific data attributes.

Parameters:

string   $name   —  Element name
mixed   $attributes   —  Attributes (either a string or an array)
array   $data   —  Element data (special captcha settings)

[ Top ]

clearCaptchaSession   [line 217]

void clearCaptchaSession( )

Destroys all captcha session data, so that the previously solved captcha re-appears as unsolved. Question and answers are discarded as well.
  • Access: public

[ Top ]

generateCaptcha   [line 121]

boolean generateCaptcha( )

Prepares the session data for the captcha.

Child classes overwrite this method do do further intialization, i.e. generating questions and answers.


Overridden in child classes as:

HTML_QuickForm2_Element_Captcha_Numeral::generateCaptcha()
Generates the captcha question and answer and prepares the session data.
HTML_QuickForm2_Element_Captcha_TextCAPTCHA::generateCaptcha()
Generates the captcha question and answer and prepares the session data.
HTML_QuickForm2_Element_Captcha_Image::generateCaptcha()
Generates the captcha question and answer and prepares the session data.

[ Top ]

getCaptchaHtml   [line 325]

string getCaptchaHtml( )

Returns the HTML for the captcha (question + input element if applicable)

Used in __toString() and to be used when $data['captchaRender'] is set to false. It is not called when the element is frozen, see getFrozenHtml() for that case. This method is also not called when the captcha has been solved, since $data['captchaSolved'] is shown then.


Overridden in child classes as:

HTML_QuickForm2_Element_Captcha_ReCaptcha::getCaptchaHtml()
Returns the HTML containing the ReCaptcha element.
HTML_QuickForm2_Element_Captcha_Numeral::getCaptchaHtml()
Returns the HTML for the captcha question and answer.
HTML_QuickForm2_Element_Captcha_TextCAPTCHA::getCaptchaHtml()
Returns the HTML for the captcha question and answer.

[ Top ]

getSession   [line 164]

HTML_QuickForm2_Element_Captcha_Session getSession( )

Returns the captcha session object
  • Return: Session object
  • Access: public

[ Top ]

getSessionVarName   [line 145]

string getSessionVarName( )

Returns the name to use for the session variable.

We include the element's ID to make sure we can use several captcha elements in one form. Also, the container IDs are included to make sure we can use the same element in different forms.

  • Return: Session variable name
  • Access: protected

[ Top ]

getType   [line 245]

string getType( )

Returns the CAPTCHA type.
  • Return: captcha type
  • Access: public

[ Top ]

getValue   [line 269]

string getValue( )

Returns the captcha answer input element value.

No value (null) when the element is disabled.

  • Return: Input value
  • Access: public

[ Top ]

setSession   [line 181]

void setSession( HTML_QuickForm2_Element_Captcha_Session $session)

Sets a new session object.

Useful for providing own session storage methods.

  • Access: public

Parameters:

HTML_QuickForm2_Element_Captcha_Session   $session   —  Session object

[ Top ]

setValue   [line 257]

void setValue( string $value)

Sets the input value
  • Access: public

Parameters:

string   $value   —  Input value

[ Top ]

validate   [line 229]

boolean validate( )

Performs the server-side validation.

Checks captcha validation first, continues with defined rules if captcha is valid

  • Return: Whether the element is valid
  • Access: protected

[ Top ]

verifyCaptcha   [line 197]

boolean verifyCaptcha( )

Checks if the captcha is solved now.

Checks the session.

Calls generateCaptcha() if it has not been called before.


Overridden in child classes as:

HTML_QuickForm2_Element_Captcha_ReCaptcha::verifyCaptcha()
Checks if the captcha is solved now.
HTML_QuickForm2_Element_Captcha_Numeral::verifyCaptcha()
Checks if the captcha is solved now.
HTML_QuickForm2_Element_Captcha_TextCAPTCHA::verifyCaptcha()
Checks if the captcha is solved now.

[ Top ]

__toString   [line 289]

string __toString( )

Renders the captcha into a HTML string

Catches all thrown exceptions - since __toString() may not throw any - and returns them as error message string.


[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:55:05 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.