You are here

public function Drupal7Post::submit in reCAPTCHA 7.2

Submit the POST request with the specified parameters.

Parameters

ReCaptcha\RequestParameters $params: Request parameters.

Return value

string Body of the reCAPTCHA response.

Overrides RequestMethod::submit

File

src/ReCaptcha/RequestMethod/Drupal7Post.php, line 28
Custom Drupal 7 RequestMehod class for Google reCAPTCHA library.

Class

Drupal7Post
Sends POST requests to the reCAPTCHA service.

Namespace

ReCaptcha\RequestMethod

Code

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 . '"]}';
  }
}