I
I
Ivan Retyukhnin2016-08-03 08:46:47
PHP
Ivan Retyukhnin, 2016-08-03 08:46:47

How to attach recaptcha to ajax form?

Essence of the question. There is a feedback form without reloading the page on AJAX. I would like to put there a recaptcha from Google. How to implement it. Preferably with examples, otherwise I'm a noob.

<form class="form-horizontal" target="_blank" method="post" id="form">
            <div class="form-group">
              <label  class="col-sm-2 control-label">Ф.И.О.:</label>
              <div class="col-sm-10">
              <input class="form-control" type="text" name="name" placeholder="Имя"  required />
              </div>
            </div>
            <div class="form-group">
              <label  class="col-sm-2 control-label">Телефон:</label>
              <div class="col-sm-10">
              <input class="form-control" type="text" name="number" pattern="^[0-9]{11}$" placeholder="Телефон"  required />
              </div>
            </div>
              <div class="form-group">
              <label class="col-sm-2 control-label">Эл. почта:</label>
              <div class="col-sm-10">
                <input class="form-control"  type="email" name="email" placeholder="E-mail"  required />
              </div>
            </div>
            <div class="form-group">
              <div class="col-sm-offset-2 col-sm-10">
                <textarea class="form-control" rows="3" name="message" placeholder="Ваше сообщение"  required></textarea>	
              </div>
            </div>
            <div class="form-group">
              <div class="col-sm-offset-2 col-sm-10">
                <button class="btn btn-default">Отправить</button>
                <label class="sucsses">СООБЩЕНИЕ ОТПРАВЛЕННО</label>
              </div>
            </div>
          </form>

$("#form").submit(function() {
        $.ajax({
            type: "POST",
            url: "http://qwerty.developer33.ru/wp-content/themes/Alliance/mail.php",
            data: $(this).serialize()
        }).done(function() {
            $(this).find("input").val("");
            $(".sucsses").fadeIn("1500");
            setTimeout(function() { $(".sucsses").fadeOut("1500"); }, 2500);   
            $("#form").trigger("reset");
        });
        return false;
    });

<?php

$recepient = "[email protected] ";

$name = trim($_POST["name"]);
$number = trim($_POST["number"]);
$email = trim($_POST["email"]);
$message = trim($_POST["message"]);

$message = "Имя: $name \nТелефон: $number \nЕmail: $email \nСообщение: $message";

$headers = 'Content-type: text/plain; charset="utf-8"';
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "From: [email protected]\r\n";
$headers .= "Reply-To: [email protected]\r\n";

$pagetitle = "Сообщение с АЛЬЯНС-сайта";
mail($recepient, $pagetitle, $message, $headers);
?>

code attached

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xmoonlight, 2016-08-03
@xmoonlight

I would like to put there a recaptcha from Google.
Why google recaptcha?
It's not easier to put something like this (you need to click on the "search" button)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question