Drupal8Post.php in reCAPTCHA 8.3
File
src/ReCaptcha/RequestMethod/Drupal8Post.php
View source
<?php
namespace Drupal\recaptcha\ReCaptcha\RequestMethod;
use ReCaptcha\ReCaptcha;
use ReCaptcha\RequestMethod;
use ReCaptcha\RequestParameters;
class Drupal8Post implements RequestMethod {
public function submit(RequestParameters $params) {
$options = [
'headers' => [
'Content-type' => 'application/x-www-form-urlencoded',
],
'body' => $params
->toQueryString(),
'http_errors' => FALSE,
];
$response = \Drupal::httpClient()
->post(ReCaptcha::SITE_VERIFY_URL, $options);
if ($response
->getStatusCode() == 200) {
return (string) $response
->getBody();
}
elseif ($response
->getStatusCode() < 0) {
return '{"success": false, "error-codes": ["' . ReCaptcha::E_CONNECTION_FAILED . '"]}';
}
else {
return '{"success": false, "error-codes": ["' . ReCaptcha::E_BAD_RESPONSE . '"]}';
}
}
}
Classes
Name |
Description |
Drupal8Post |
Sends POST requests to the reCAPTCHA service with Drupal 8 httpClient. |