我想输入 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));