maybe it's a duplicate question, but i didn't find appropriate answers on it; most of them are relying on plugin and Bootstrap site. I made a custom contact form that send HTML email template via AJAX with Jquery form validation plugin which working great! And validation is working properly; but i have one problem to finish the task; i need to compare if the value entered in the field, is the value provided by the php captcha. Or is there any other solution that can check or restricted the right value in Jquery or Javascript. Here is my form validation:
// form validation
$('#contact_form').validate({
onkeyup: false,
onclick: false,
debug: true,
rules:{
fullname:{
required :true,
},
email:{
required :true,
},
subject:{
required :true,
},
message:{
required :true,
},
securitycode: {
required :true,
remote: {
url: '/includes/captcha/check-captcha.php',
// type: 'post',
data: {
capvalue: function() {
return $( '#captcha' ).val();
}
}
}
}
},
messages: {
fullname: {
required: '*your name is required.'
},
email:{
required: '*email is required.'
},
subject:{
required: '*subject name is required.'
},
message:{
required: '*message is required.'
},
securitycode: {
required: '*Enter the right captcha code.'
}
}
});
In the validation, i'm interested in rules for the field "securitycode"; i can't get the right url with some wordpress build functions. i get this error on the console log "GET http://localhost/includes/captcha/check-captcha.php?securitycode=05c25&capvalue= 404 (Not Found)"; the link missed only the root site folder name after the "localhost";
and the HTML file for the field check is:
<div class=" captcha form-group captcha_style">
<input type="text" name="securitycode" id="securitycode" class=" form-control" maxlength="5">
<div class="button captcode">
<img src="<?php bloginfo('template_url') ?>/includes/captcha/captcha.php" id="captcha" alt="Captcha"/>
<span class="refresh-captcha"><i class="fa fa-refresh"></i></span>
</div>
</div>
i found a snippet to put in file check-captcha.php, like this :
<?php
if (!isset($_SESSION)) session_start();
if(strtolower($_REQUEST['securitycode']) == $_SESSION['captcha']) echo '1';
else '0';
?>
Any contribution would be appreciate, Thanks!
</div>