GF_Field_CAPTCHA
Source: includes/fields/class-gf-field-captcha.php:8
Details
- Kind:
class - Namespace:
(global) - Extends: GF_Field
Properties
| Property | Type | Description |
|---|---|---|
$type | string | |
$duplicatable | bool | Whether there can be more than one of this field type per form. |
$repeatable | bool | Whether the field can be used in a repeater. |
$_supports_state_validation | bool | Indicates if this field supports state validation. |
Methods
| Method | Description |
|---|---|
__construct() | The reCAPTCHA field constructor. |
set_recaptcha_response() | Add recaptcha response to the AJAX request result. |
get_form_editor_field_description() | Returns the field's form editor description. |
get_form_editor_field_icon() | Returns the field's form editor icon. |
get_field_sidebar_messages() | Returns the warning message to be displayed in the form editor sidebar. |
maybe_remove_recaptcha_v2() | Recaptcha v2 does not work in conversational forms, so we have to remove it. |
validate() | Validate the reCAPTCHA field. |
validate_recaptcha() | Validates the reCAPTCHA response. |
verify_decoded_response() | Verifies that the decoded response meets the requirements for submitting the form. |
get_site_key() | Get the saved site key. |
get_secret_key() | Get the saved secret key. |
get_posted_recaptcha_response() | Get the value of the reCAPTCHA response input. |
verify_recaptcha_response() | Validate the reCAPTCHA token provided by Google. |
get_encoded_recaptcha_response() | Encode the reCAPTCHA response with details from Google. |
post_convert_field() | Actions to be performed after the field has been converted to an object. |
is_state_validation_supported() | Determines if this field will be processed by the state validation. |
get_values_for_state_hash() | Prepares the value that will be hashed on form display as part of the state. |
get_value_for_state_validation() | Returns the value to use when the state is validated. |
Method Reference
__construct()
public function __construct( $data=[] )
The reCAPTCHA field constructor.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$data | [] |
Since: 2.8.13
Source: includes/fields/class-gf-field-captcha.php:70
set_recaptcha_response()
public static function set_recaptcha_response( $result )
Add recaptcha response to the AJAX request result.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$result | array | The result of the AJAX validation and submission request. |
Returns
mixed
Since: 2.9.0
Source: includes/fields/class-gf-field-captcha.php:90
get_form_editor_field_description()
public function get_form_editor_field_description()
Returns the field's form editor description.
Returns
string
Since: 2.5
Source: includes/fields/class-gf-field-captcha.php:118
get_form_editor_field_icon()
public function get_form_editor_field_icon()
Returns the field's form editor icon.
This could be an icon url or a gform-icon class.
Returns
string
Since: 2.5
Source: includes/fields/class-gf-field-captcha.php:131
get_field_sidebar_messages()
public function get_field_sidebar_messages()
Returns the warning message to be displayed in the form editor sidebar.
Returns
string|array
Since: 2.8
Source: includes/fields/class-gf-field-captcha.php:160
maybe_remove_recaptcha_v2()
public static function maybe_remove_recaptcha_v2( $form )
Recaptcha v2 does not work in conversational forms, so we have to remove it.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$form |
Returns
void
Since: 2.8.13
Source: includes/fields/class-gf-field-captcha.php:208
validate()
public function validate( $value, $form )
Validate the reCAPTCHA field.
This method always gets called on the last page of a form, as well as on the page where the field is assigned.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$value | array | string | The field value. | |
$form | array | The form data. |
Since: Unknown
Source: includes/fields/class-gf-field-captcha.php:235
validate_recaptcha()
public function validate_recaptcha( $form )
Validates the reCAPTCHA response.
In our application flow, we create a decoded string out of the reCAPTCHA service response if the reCAPTCHA field is added to the form on a page other than the last page. We therefore first attempt to validate the decoded response, falling back to validating the reCAPTCHA with a request to Google.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$form | array | The form data. |
Returns
bool
See Also
Since: unknown
Source: includes/fields/class-gf-field-captcha.php:308
verify_decoded_response()
public function verify_decoded_response( $form, $response )
Verifies that the decoded response meets the requirements for submitting the form.
Returns false if the decoded response doesn't exist or the reCAPTCHA field is on the last page, as we'll want regular validation at that point instead.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$form | array | The form data. | |
$response | string | The encoded response to verify. |
Returns
bool
Since: 2.4.24
Source: includes/fields/class-gf-field-captcha.php:340
get_site_key()
public function get_site_key()
Get the saved site key.
Returns
string
Since: 2.4.24
Source: includes/fields/class-gf-field-captcha.php:374
get_secret_key()
public function get_secret_key()
Get the saved secret key.
Returns
string
Since: 2.4.25
Source: includes/fields/class-gf-field-captcha.php:389
get_posted_recaptcha_response()
public function get_posted_recaptcha_response()
Get the value of the reCAPTCHA response input.
When user clicks on the "I'm not a robot" box, the response token is populated into a hidden field by Google. If the current form is a multi-page form and the reCAPTCHA field is on a page other than the last page, this value will return an openssl encoded string with the Google reCAPTCHA validation data and some supplemental validation data instead.
Returns
string
See Also
Since: 2.4.24
Source: includes/fields/class-gf-field-captcha.php:411
verify_recaptcha_response()
public function verify_recaptcha_response( $response, $secret_key=null )
Validate the reCAPTCHA token provided by Google.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$response | string | The token to verify. | |
$secret_key | null | null | The secret key for reCAPTCHA verification. |
Returns
bool
Since: unknown
Source: includes/fields/class-gf-field-captcha.php:425
get_encoded_recaptcha_response()
public function get_encoded_recaptcha_response( $form, $response )
Encode the reCAPTCHA response with details from Google.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$form | array | The form data. | |
$response | string | The posted response data. |
Returns
string
Since: 2.4.24
Source: includes/fields/class-gf-field-captcha.php:581
post_convert_field()
public function post_convert_field()
Actions to be performed after the field has been converted to an object.
Returns
void
Since: 3.0
Source: includes/fields/class-gf-field-captcha.php:850
is_state_validation_supported()
public function is_state_validation_supported()
Determines if this field will be processed by the state validation.
Returns
bool
Since: 3.0
Source: includes/fields/class-gf-field-captcha.php:865
get_values_for_state_hash()
public function get_values_for_state_hash( $value )
Prepares the value that will be hashed on form display as part of the state.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$value | string | array | The default value. |
Returns
null|array
Since: 3.0
Source: includes/fields/class-gf-field-captcha.php:878
get_value_for_state_validation()
public function get_value_for_state_validation( $value )
Returns the value to use when the state is validated.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$value | string | array | The submitted value. |
Returns
array
Since: 3.0
Source: includes/fields/class-gf-field-captcha.php:896