简体   繁体   中英

how to get recaptcha client verification parameter g-recaptcha-response after user confirms he is not a robot?

I am trying to implement Google recaptcha in a form. The form issues an HTTP post request to a server where it sends the for data as a JSON object.

I added Google reCAPTCHA just before the form submit button with the following div tag:

     <div class="g-recaptcha" data-sitekey="{SITE_KEY}"></div>

Also I added the required JavaScript file in the head tag:

 <script src='https://www.google.com/recaptcha/api.js'></script>

Now the submit button issues a request to a JavaScript function as follows: hence I am using Angular JS

  $scope.issueVideoUploadRequest = function () {

    var requestVideoUploadParameters = {
        videoSource: $scope.videoSource,
        title: $scope.title,
        description: $scope.description,
        videoLanguage: $scope.language,
        tagsList: $scope.tagsList
    };
    $http({
        method: "POST",
        dataType: "json",
        data: requestVideoUploadParameters,
        url: 'http://localhost:8080/OampSeniorProjectV2/rs/content/requestUploadForm'
    }).success(function (response, status, headers) {
        $scope.alertMessageVideoRequest = response;
        alert(response);
    }).error(function (response, status, headers, config) {
        $scope.reloadPage();
    });
};

The form is submitted to a REST services.

The question is, where to find the g-recaptcha-response parameter so I send it back to the server along with the form JSON object? As I need this response value to perform the server side user verification.

I was following the documentation posted here

grecaptcha.getResponse(widget_id);

This will give you the response of the recaptcha. Use this in your form submit function if you're using Angular.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM