I
I
i_ikigai2019-09-26 11:30:38
PHP
i_ikigai, 2019-09-26 11:30:38

How to put google captcha on landing page?

I see from the links in Google that you need to insert the codes that Google gives out. Do they need to be directly integrated into their inverse form? Or are there easier options?

<?php
$name = $_POST['name'];
$phone = $_POST['phone'];
$city = $_POST['city'];
$subject = $_POST['subject'];
$email = $_POST['email'];
$message = $_POST['message'];
 
header('Content-Type: application/json');
if ($name === ''){
  print json_encode(array('message' => 'Введите имя', 'code' => 0));
  exit();
}
$phone = $_POST['phone'];
if(!preg_match('/^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$/', $phone)){
    exit(print json_encode(array('message' => 'Некорректный телефон', 'code' => 0)));
}
// if ($city === ''){
//   print json_encode(array('message' => 'Введите населенный пункт', 'code' => 0));
//   exit();
// }
 
// if ($email === ''){
//   print json_encode(array('message' => 'Введите почту', 'code' => 0));
//   exit();
//   }
//   else {
//   if (!filter_var($email, FILTER_VALIDATE_EMAIL)){
//   print json_encode(array('message' => 'Введите верный адрес почты', 'code' => 0));
//   exit();
//   }
// }
if ($subject === ''){
  print json_encode(array('message' => 'Введите объект оценки', 'code' => 0));
  exit();
}
// if ($message === ''){
//   print json_encode(array('message' => 'Напишите подробный адрес и объект оценки', 'code' => 0));
//   exit();
// }
$content="Имя заказчика: $name \nТелефон заказчика: $phone \nРасположение заказчика: $city \nEmail заказчика: $email \nСообщение: $message";
$recipient = "[email protected]";
// $mailheader = "From: $email \r\n";
mail($recipient, $subject, $content, $mailheader) or die("Ошибка!");
print json_encode(array('message' => 'Ваше обращение отправлено, наши специалисты с вами свяжутся!', 'code' => 1));
exit();
?>

<form class="formmargin" id="contact-form" name="contact-form" action="mail.php" method="POST" onsubmit="return validateForm()">
<div class="form-row font-weight-bolder">
<div class="col-md-6 md-form">
<input type="text" id="name" name="name" class="form-control" required>
<label for="name">Имя</label>
</div>
<div class="col-md-6 md-form">
<input type="text" id="phone" name="phone" class="form-control" required>
<label for="phone">Телефон</label>
</div>
<div class="col-md-6 md-form">
<input type="text" id="city" name="city" class="form-control" required>
<label for="city">Введите населенный пункт</label>
</div>
<div class="col-md-6 md-form">
<input type="text" id="subject" name="subject" class="form-control" required>
<label for="subject">Объект оценки</label>
</div>
</div>
<div class="form-row">
<div class="col-md-6 md-form  font-weight-bolder">
<input type="text" id="email" name="email" class="form-control" required>
<label for="email">E-mail</label>
</div>
</div>
<div class="md-form ">
<textarea id="message" name="message" class="md-textarea form-control" rows="3" required></textarea>
                                            <label>Напишите полный адрес обьекта оценки</label>
</div>

</form>
<div class="center-on-small-only">
                                          
<button class="btn btn-primary" type="submit" onclick="validateForm()">Отправить</button>
<button type="button" class="btn btn-primary " data-dismiss="modal">Закрыть</button>
</div>

function validateForm() {
 
    document.getElementById('status').innerHTML = "Отправка...";
    formData = {
        'name'     : $('input[name=name]').val(),
        'phone'    : $('input[name=phone]').val(),
        'city'     : $('input[name=city]').val(),
        'subject'  : $('input[name=subject]').val(),
        'email'    : $('input[name=email]').val(),
        'message'  : $('textarea[name=message]').val()
    };
 
 
   $.ajax({
    url : "mail.php",
    type: "POST",
    data : formData,
    success: function(data, textStatus, jqXHR)
    {
 
        $('#status').text(data.message);
        if (data.code) //If mail was sent successfully, reset the form.
        $('#contact-form').closest('form').find("input[type=text], textarea").val("");
    },
    error: function (jqXHR, textStatus, errorThrown)
    {
        $('#status').text(jqXHR);
    }
});
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xmoonlight, 2019-09-26
@i_ikigai

Here ( verify )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question