HCaptcha extends AbstractCaptcha
hCaptcha integration
Table of Contents
Properties
| $Html | |
| $js_api | |
| $options | |
| $verify_api |
Methods
| __construct() | Initialize hCaptcha |
| buildHtml() | Builds the HTML content to render the reCaptcha |
| errors() | Retrieves any errors associated with the captcha |
| getName() | Returns the name of the captcha provider |
| getOptionFields() | Gets a list of the options input fields |
| setOptions() | Sets hCaptcha options |
| verify() | Verifies whether or not the captcha is valid |
| setErrors() | Sets the given errors |
Properties
$Html
protected
Html
$Html
An instance of Html
$js_api
private
string
$js_api
= 'https://hcaptcha.com/1/api.js'
The hCaptcha JavaScript API URL
$options
private
array<string|int, mixed>
$options
= []
An array of options
$verify_api
private
string
$verify_api
= 'https://hcaptcha.com/siteverify'
The hCaptcha verification API URL
Methods
__construct()
Initialize hCaptcha
public
__construct() : mixed
buildHtml()
Builds the HTML content to render the reCaptcha
public
buildHtml() : string
Return values
string —The HTML
errors()
Retrieves any errors associated with the captcha
public
errors() : array<string|int, mixed>
Return values
array<string|int, mixed> —An array of errors
getName()
Returns the name of the captcha provider
public
getName() : string
Return values
string —The name of the captcha provider
getOptionFields()
Gets a list of the options input fields
public
getOptionFields([array<string|int, mixed> $vars = [] ]) : InputFields
Parameters
- $vars : array<string|int, mixed> = []
-
An array containing the posted fields
Return values
InputFields —An object representing the list of input fields
setOptions()
Sets hCaptcha options
public
setOptions(array<string|int, mixed> $options) : mixed
Parameters
- $options : array<string|int, mixed>
-
An array of options including:
- site_key The hCaptcha site key
- secret_key The hCaptcha secret key
- lang The user's language (e.g. "en" for English)
- ip_address The user's IP address (optional)
verify()
Verifies whether or not the captcha is valid
public
verify(array<string|int, mixed> $data) : bool
Parameters
- $data : array<string|int, mixed>
-
An array of data to validate against, including:
- response The value of 'h-captcha-response' in the submitted form
Return values
bool —Whether or not the captcha is valid
setErrors()
Sets the given errors
protected
setErrors(array<string|int, mixed> $errors) : mixed
Parameters
- $errors : array<string|int, mixed>
-
An array of error messages in the format:
- ['name' => ['type' => 'Error Message']]