0
頁面
我有這樣的代碼在頁面的驗證碼需要的地方:驗證碼形式提交無需重新加載
<?php
/** Validate captcha */
if (!empty($_REQUEST['captcha'])) {
if (empty($_SESSION['captcha']) || trim(strtolower($_REQUEST['captcha'])) !== $_SESSION['captcha']) {
echo '<script type="text/javascript">'
, 'fail();'
, '</script>';
}
if (empty($_SESSION['captcha']) || trim(strtolower($_REQUEST['captcha'])) == $_SESSION['captcha']) {
echo '<script type="text/javascript">'
, 'success();'
, '</script>';
}
$request_captcha = htmlspecialchars($_REQUEST['captcha']);
unset($_SESSION['captcha']);
}
if (empty($_REQUEST['captcha'])) {
echo '<script type="text/javascript">'
, 'fail();'
, '</script>';
}
?>
的形式如下:
<form>
<img src="../captcha.php"/>
<input type="text" name="captcha" /></div>
<input name="submit">
</form>
關於什麼的captcha.php我不認爲這是必要的,但如果是這樣,請讓我知道。
我需要它提交驗證碼而不刷新頁面。
我已經試過這沒有任何成功:
$(function() {
$('form').bind('click', function (event) {
event.preventDefault();// using this page stop being refreshing
$.ajax({
type: 'POST',
url: '',
data: $('form').serialize(),
success: function() {
alert('form was submitted');
}
});
});
});
這有幫助,但如何檢查一切就像在PHP? – Simon
我不太清楚你的意思。你能詳細說明你需要幫助的部分嗎? –
3部分喜歡'if(empty($ _ SESSION ['captcha'])|| trim(strtolower($ _ REQUEST ['captcha']))!== $ _SESSION ['captcha'])巫婆檢查代碼是否輸入正確,如果沒有,一個只是提交功能(我沒有找到另一種工作方式來檢查該字段是否爲空) – Simon