0

I have a form with google reCaptcha v2. But in my code when person didn't check the icon I'm not a robot, the code sends the person to a new page with the message Please check the the captcha form.

I need when person doesn't check the icon I'm not a robot, he/she stays on the same page with the message: Please check the the captcha form. Here is an example of what I want

I have a contact form (name, telephone and text message)

<?php
    $email;$comment;$captcha;
    if(isset($_POST['email'])){
      $email=$_POST['email'];
    }if(isset($_POST['comment'])){
      $email=$_POST['comment'];
    }if(isset($_POST['g-recaptcha-response'])){
      $captcha=$_POST['g-recaptcha-response'];
    }
    if(!$captcha){
      echo '<h2>Please check the the captcha form.</h2>';
      exit;
    }
    $secretKey = "************";
    $ip = $_SERVER['REMOTE_ADDR'];
    $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
    $responseKeys = json_decode($response,true);
    if(intval($responseKeys["success"]) !== 1) {
      echo '<h2>You are spammer ! Get the @$%K out</h2>';
    } else {
      echo '<h2>Thanks for posting comment.</h2>';
    }

Can you help me with it?

DarkBee
  • 16,592
  • 6
  • 46
  • 58
Sergiy K.
  • 1
  • 1

1 Answers1

0

I think you should use #Javascript to validate that clients has been checked your captcha first. Then send the submit form i thef captcha is checked.

Đào Minh Hạt
  • 2,742
  • 16
  • 20