2

I want to create validation for recaptcha filed using jQuery Validation Plugin and also php with Session.

jQuery

I am useing (https://jqueryvalidation.org/) this jquery plugin for form validation and i do it. but i want to create validation for recaptcha filed using this plugin, but i can't create it. Here is a validation for google recaptcha v1.0 using these plugin. Please help me to create validation for google recaptcha v2.0 (filed) using this pulgin.

PHP

I am also want to create validation use $_SESSION and i am try to create it, in my (signup-process.php) page and i print the session message in my form page under the recaptcha filed. it's not working :(

====== Please help me to create validation for recaptcha filed using this both way.

HTML

<form action="signup-process.php" method="post" id="signupForm">
  <input class="form-control" type="text" name="name" id="name">
   <div class="g-recaptcha" data-sitekey="my-key"></div>

 <!--Session validation message-->
  /*<?php if(isset($_SESSION["ReC"]) && !empty($_SESSION["ReC"])){
      echo $_SESSION["ReC"];
       unset($_SESSION["ReC"]); }?> */

     <input class="btn btn-block" type="submit" value="Sign Up" name="submitted">
  </form>

JS

$("#signupForm").validate({
        rules: {
            name: "required",
        },
        messages: {
            name: "Please enter your name",
        }
    });

signup-process.php

if(isset($_POST['g-recaptcha-response'])&& !empty($_POST['g-recaptcha-response'])){

    $secret = "my-key";
    $ip = $_SERVER['REMOTE_ADDR'];
    $captcha = $_POST['g-recaptcha-response'];
    $rsp  = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=$secret&response=$captcha&remoteip$ip");

    $arr = json_decode($rsp,TRUE);
    if($arr['success'] == "true"){
        echo 'Done';
    }else{
        echo 'SPam';
} else {
    $_SESSION["ReC"]="Please select captcha";
        header("location:signup.php");
}
djmzfKnm
  • 26,679
  • 70
  • 166
  • 227
  • 2
    Possible duplicate of [New reCaptcha with jQuery Validation Plugin](http://stackoverflow.com/questions/29563822/new-recaptcha-with-jquery-validation-plugin) – Vishnu Bhadoriya Aug 25 '16 at 17:05
  • 1
    @Vishnu Bhadoriya, It's not working as i want. [recaptcha 2 validation](http://formvalidation.io/addons/recaptcha2/#example) I want like this validation plugin work but this is a premium plugin. –  Aug 25 '16 at 18:37
  • 1
    Hello @Vishnu Bhadoriya, Thanks so so much it's working now. but i couldn't understand why it's not work before. Thanks again for your help :) –  Aug 30 '16 at 17:08

1 Answers1

1

@NK If you apply your php validation message On top of the form tag. it will works.

like this

 <!--Session validation message-->
 <?php if(isset($_SESSION["ReC"]) && !empty($_SESSION["ReC"])){
    echo $_SESSION["ReC"];
    unset($_SESSION["ReC"]); }
?>

<form action="signup-process.php" method="post" id="signupForm">
  <input class="form-control" type="text" name="name" id="name">
  <div class="g-recaptcha" data-sitekey="my-key"></div>
  <input class="btn btn-block" type="submit" value="Sign Up" name="submitted">
</form>
MD Iyasin Arafat
  • 763
  • 1
  • 12
  • 22
  • 1
    For this issues i can't continue my work. It's work now properly :) Thank you so much @MD Iyasin Arafat –  Aug 27 '16 at 15:42