Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

196
Visualizações
reCaptcha field as required

I am trying to use recaptcha in a form, however, I am having trouble to set it as required. I tried to use the code of the first two answers of this question, however, none of them worked.

Here is my header code:

<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.15.0/jquery.validate.min.js"></script>
<script src="https://www.google.com/recaptcha/api.js"></script>

Here is my body code (I tried first the accepted question):

<form action="some-page.php">
    <fieldset>
        <legend>Personal information:</legend>
        First name:<br>
        <input type="text" name="firstname" value="Name" required><br> Last name:<br>
        <input type="text" name="lastname" value="Last Name" required><br><br>
    <div class="g-recaptcha" data-sitekey="xxxx"></div>
        <input type="hidden" name="recaptcha" data-rule-recaptcha="true">
        <input type="submit" value="Submit">
    </fieldset>
</form>

<script>
    $('form').validate({
        ignore: '.no-validation'
    });

    // Add our validation method for reCaptcha: 
    $.validator.addMethod("recaptcha", function(value, element) {
        var grecaptcha = window.grecaptcha || null;
        return !grecaptcha || grecaptcha.getResponse();
    }, "Please fill reCAPTCHA");
</script>
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

function validateForm() {	
    var recaptcha = document.forms["myForm"]["g-recaptcha-response"].value;
    if (recaptcha == "") {
        alert("Please fill reCAPTCHA");
        return false;
    }
}
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.15.0/jquery.validate.min.js"></script>
<script src="https://www.google.com/recaptcha/api.js"></script>



<form name="myForm" action="login.php"  onsubmit="return validateForm()" method="post">
    <fieldset>
        <legend>Personal information:</legend>
        First name:<br>
        <input type="text" name="firstname" value="Name" required><br> Last name:<br>
        <input type="text" name="lastname" value="Last Name" required><br><br>
    <div class="g-recaptcha" data-sitekey="6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI"></div>
        <input type="hidden" name="recaptcha" data-rule-recaptcha="true">
        <input type="submit" value="Submit">
    </fieldset>
</form>

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda