G
G
geepis2019-08-09 21:13:15
reCAPTCHA
geepis, 2019-08-09 21:13:15

Who can help with installing recaptcha?

help me understand the code there is such a code
form

<div id="base-modal" class="modal fade" tabindex="-1" data-width="420">
  <form action="/users/login" url="/" method="POST" class="form_0" style="padding:0px; margin:0px;">
    <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
      <h4 class="modal-title">{lang=Авторизация}</h4>
    </div>
    <div class="modal-body">
      <input style="width:100%;" class="form-control" name="data[email]" placeholder="E-mail" type="text">
      <br>
      <input style="width:100%;" class="form-control" name="data[password]" type="password" placeholder="{lang=Пароль}">
        	
    </div>
    <div class="modal-footer">

                       <div class="g-recaptcha" data-sitekey="6LdjULAUAAAAACwf3s0akZURbxhvJd09mw8oAFX3"></div>

      <a href="/users/signup" class="btn btn-default ymodal">{lang=Регистрация}</a>
      <a href="/users/recovery" class="btn btn-default ymodal">{lang=Восстановить}</a>
      <button type="submit" class="btn btn-primary">{lang=Войти}</button>
      <a type="submit" class="btn btn-icon-only blue loginvk"><i class="fa fa-vk"></i></a>
    </div>
  </form>

 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>

        <script type="text/javascript">
            $("form").submit(function(e){
                e.preventDefault();

                var login = $("input").val();

                $.ajax({
                    url: 'handler.php',
                    type: "post",
                    data: "login=" + login + "&g-recaptcha-response=" + grecaptcha.getResponse(),
                    success: function(data) {
                        if(data === 'ok') {
                            window.location.href ='/';
                        } else {
                            console.log(data);
                        }
                    }
                })
            });
        </script>

<?php

if($_POST['g-recaptcha-response']) {
  $captcha = $_POST['g-recaptcha-response'];
  $secret = "6LdjULAUAAAAAJ09xC7TUnFK41VIi8CoTOMEfAwi";

  $json = json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=". $secret . "&response=" . $captcha), true);

  if($json['success']) {
      echo "ok";
  } else {
      echo "recaptcha error";
  }
}  else {
    echo "Вы не ввели значение recaptcha";
}

 ?>

and handler
$(document).on('submit', '.form_0', function (e) {
        e.preventDefault();
        var url = $(this).attr('url');

        $(this).ajaxSubmit({
            dataType: 'json',
            data: {ajax_f: '1'},
            success: function (data) {
                ajax_result(data);
                if (data.r) {
                    href_go(url);
                }
            },
            beforeSend: function () {
                $('.preloader-bar').css('top','0px');
                $('#loader-ajax').css('display', 'block');
            },
            complete: function () {
                $('.preloader-bar').css('top','-34px');
                $('#loader-ajax').css('display', 'none');
            }
        });
    });

I know that there should be something like this but I can't attach it
$user['name'] = $_REQUEST['name'];
$user['surname'] = $_REQUEST['surname'];


echo json_encode($user);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2019-08-09
@geepis

Google will help, Recaptcha

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question