class Drupal7Post in reCAPTCHA 7.2
Sends POST requests to the reCAPTCHA service.
Hierarchy
- class \ReCaptcha\RequestMethod\Drupal7Post implements RequestMethod
Expanded class hierarchy of Drupal7Post
File
- src/
ReCaptcha/ RequestMethod/ Drupal7Post.php, line 17 - Custom Drupal 7 RequestMehod class for Google reCAPTCHA library.
Namespace
ReCaptcha\RequestMethodView source
class Drupal7Post implements RequestMethod {
/**
* Submit the POST request with the specified parameters.
*
* @param ReCaptcha\RequestParameters $params
* Request parameters.
*
* @return string
* Body of the reCAPTCHA response.
*/
public function submit(RequestParameters $params) {
$options = array(
'headers' => array(
'Content-type' => 'application/x-www-form-urlencoded',
),
'method' => 'POST',
'data' => $params
->toQueryString(),
);
$response = drupal_http_request(ReCaptcha::SITE_VERIFY_URL, $options);
if ($response->code == 200 && isset($response->data)) {
// The service request was successful.
return $response->data;
}
elseif ($response->code < 0) {
// Negative status codes typically point to network or socket issues.
return '{"success": false, "error-codes": ["' . ReCaptcha::E_CONNECTION_FAILED . '"]}';
}
else {
// Positive none 200 status code typically means the request has failed.
return '{"success": false, "error-codes": ["' . ReCaptcha::E_BAD_RESPONSE . '"]}';
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Drupal7Post:: |
public | function |
Submit the POST request with the specified parameters. Overrides RequestMethod:: |