B
B
BonBon Slick2017-01-04 14:28:02
Google
BonBon Slick, 2017-01-04 14:28:02

Google Recaptcha validation - 422 (Unprocessable Entity)?

Laravel 5.3
https://github.com/greggilbert/recaptcha
Form:

<form action="post" action="/formsubmit" id="searchForm">
  {{ csrf_field() }}
  //вызов модального окна по клику на кнопку
  <button class="btn btn-default btn-block" type="button" data-toggle="modal" data-target="#myModal"><b>Голосовать!</b></button>
  <div id="myModal" class="modal fade" role="dialog">
    <div class="modal-dialog">
    //модальное окно
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal"><i class="fa fa-times"></i></button>
          <h4 class="modal-title">Тайтл модального окна</h4>
        </div>
        <div class="modal-body">
        //каптча
          {!! Recaptcha::render() !!}
        </div>
        <div class="modal-footer">
        //по клику, идет аджакс запрос, где идет валидация формы и рекаптчи
          <button type="button" id="submit-form" class="btn btn-default btn-block" data-dismiss="modal" onclick="submitForm(event)">Подтвердить!</button>
        </div>
      </div>
    </div>
  </div>
</form>

scripts:
function submitForm(event) {
                          var token = $('input[name="_token"]').val();
                          $.ajax({
                            url: '/formsubmit',
                            type: 'POST',
                            data: {
                              '_token': token,
                            },
                          })
                          .done(function(data) {
                            console.log(data);
                          })
                          .fail(function() {
                            console.log("ERROR");
                          });
                        }

PHP:
public function submitForm(Request $request)
  {
    $this->validate($request, [
      'g-recaptcha-response' => 'required|recaptcha',
      ]);
    return  'Validated!';
  }

Where am I wrong, why doesn't the captcha validate?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question