您好,我有以下代码,它可以工作,我的意思是它可以很好地验证验证码,但它不会在 sign_form.php 中发布值
<script>
$(document).ready(function() {
$('#Send').click(function() {
$.post("sign_form.php?"+$("#sign_form").serialize(), {
}, function(response){
if(response==1)
{
$("#after_submit").html('');
$("#Send").after('<div id="after_submit">Your message has been submitted.</div>');
change_captcha();
clear_form();
}
else
{
$("#after_submit").html('');
$("#Send").after('<div id="after_submit">Error ! invalid captcha code .</div>');
}
});
return false;
});
// refresh captcha
$('img#refresh').click(function() {
change_captcha();
});
function change_captcha()
{
document.getElementById('captcha').src="get_captcha.php?rnd=" + Math.random();
}
function clear_form()
{
$("#name").val('');
$("#email").val('');
$("#message").val('');
}
});
表格代码
<form id="sign_form" name="sign_form" method="POST" action="#">
<fieldset class="step">
<legend>Podepsat tuto petici</legend>
<p>
<label for="first_name">Křestní jméno:</label>
<input type="text" name="first_name" id="first_name">
</p>
<p>
<label for="last_name">Příjmení:</label>
<input type="text" name="last_name" id="last_name">
</p>
<p>
<label for="email">Email:</label>
<input type="text" name="email" id="email">
</p>
<p>
<label for="email">Mesto:</label>
<input type="text" name="city" id="city">
</p>
<p>
<div id="wrap" align="center">
<img src="get_captcha.php" alt="" id="captcha" />
<br clear="all" />
<input name="code" type="text" id="code">
</div>
<img src="refresh.jpg" width="25" alt="" id="refresh" />
</p>
<p>
<input type="hidden" value="'.$id.'" name="id" id="id">
</p>
<p>
Emailová adresa nebude zveřejněna a nebude <br>předána žádné třetí straně.
</p>
<p>
<button type="submit" value="send" id="Send"></button>
<div id="status"></div>
</p>
</form>
sign_form.php 代码
session_start();
require_once('engine/db.php');
mysql_query("SET NAMES utf8");
if(($_REQUEST['code'] == $_SESSION['random_number']) || @strtolower($_REQUEST['code']) == strtolower($_SESSION['random_number']) )
{
$first_name=$_POST['first_name'];
$last_name=$_POST['last_name'];
$email=$_POST['email'];
$city=$_POST['city'];
$id=$_POST['id'];
$insert = "INSERT INTO petition_vote
(id_petition,first_name,last_name,email,city)
VALUES ('".$id."','".mysql_real_escape_string($first_name)."','".mysql_real_escape_string($last_name)."','".mysql_real_escape_string($email)."','".mysql_real_escape_string($city)."')";
//$add_member = mysql_query($insert);
$result = mysql_query($insert)
or die("query failed: " . mysql_error());
echo 1;
}
else
{
echo 0;
}
我对代码进行了更新,但随后它刷新了我的页面
if(response==1)
{
submitform();
}
else
…
function submitform()
{
document.forms.sign_form.submit();
}