我想放入securimage的验证码,但我的代码有问题。它没有读取检查验证码是否正确但仅保存数据并忽略验证码的条件。这是我的jquery代码,它允许我在我的数据库上保存数据而无需重新加载
(function() {
if($('#contactform').length) {
var $form = $('#contactform'),
$loader = '<img src="images/preloader.gif" alt="Loading..." />';
$form.append('<div class="hidden" id="contact_form_responce">');
var $response = $('#contact_form_responce');
$response.append('<p></p>');
$form.submit(function(e){
$response.find('p').html($loader);
$.post("php/contact-send.php", $("#contactform").serialize(), function(response) {
$response.find('img').remove();
$response.find('p').removeClass().addClass('success type-2');
$response.find('p').append('Your email has been sent!');
$form.find('input:not(input[type="submit"], button), textarea, select').val('').attr( 'checked', false );
$response.delay(1500).hide(400);
});
e.preventDefault();
});
}
})();
/* end Contact Form */
这是我的PHP代码处理我的数据
require_once "../includes/database.php";
session_start();
include_once $_SERVER['DOCUMENT_ROOT'] . '/pcf/securimage/securimage.php';
$securimage = new Securimage();
if ($securimage->check($_POST['captcha_code']) == false) {
echo "<script language='javascript' type='text/javascript'>alert('Invalid Captcha!')</script>";
echo "<script language='javascript' type='text/javascript'>window.open('contact.php?alink=c','_self')</script>";
exit;
}
$cname=$_POST['name'];
$cemail=$_POST['email'];
$cmessage=$_POST['message'];
$date=date("Y-m-d");
$sql = "INSERT INTO messages (sendername,senderemail,message,datesent) VALUES (:name,:email,:message,:date)";
$qry = $db->prepare($sql);
$qry->execute(array(':name'=>$cname,':email'=>$cemail,':message'=>$cmessage,':date'=>$date));