0
How can I make so that the user enters the wrong captcha, the validation occurs without giving the post? I have the following code:
<?php session_start(); ?>
....
<div class="control-group">
<div class="controls">
<label>Digite o código abaixo:</label>
<?php
$codigoCaptcha = substr(md5(time()) ,0, 5);
if(!isset($_SESSION["Captcha"])){
$_SESSION["Captcha"] = $codigoCaptcha;
}
echo "<div id='captcha'>".$_SESSION["Captcha"]."</div>";
?>
<input type="text" class="form-control" name="Captcha" title="Digite o código <?php echo $_SESSION["Captcha"]; ?>" required />
</div>
</div>
<div align="center" style="margin-top: 10px">
<button type="submit" id="submit" class="btn btn-primary btn-lg col-lg-12" title="Enviar mensagem">Enviar</button><br />
</div>
The result is this:
it is possible to create captcha in PHP and validate with Jquery?
I tried to do it that way, but it doesn’t work:
<script>
$(function(){
$("#submit").click(function(){
var captcha = $(this).attr('captcha');
if(captcha != <?php echo $_SESSION["Captcha"]; ?>){
alert("Caracteres errados");
}else{
alert("OK");
}
});
});
</script>
Perfect Jrd. It worked! Thank you so much.
– user24136