我剛剛幫助了一些功能和回調,以獲得表單一旦提交關於該動畫:不同的功能形式成功和形式驗證消息
$("#message").show().delay(5000).fadeOut('fast', function(){
$("#slide_panel").slideToggle("slow");
});
雖然,這個問題我現在已經是,如果有人必須提交表單而不輸入正確的詳細信息,則還會彈出錯誤消息(與感謝消息彈出相同的div「消息」),延遲5秒鐘,然後關閉表單。
當然,我不希望它關閉窗體,而是顯示錯誤消息5秒鐘,然後淡出錯誤消息。
什麼我需要在這裏添加:
function(data){
document.getElementById('message').innerHTML = data;
$('#message').slideDown('slow');
$('#contactform img.loader').fadeOut('fast',function()
{$(this).remove()});
$('#submit').removeAttr('disabled');
if(data.match('success') != null);
$('#name').val("");
$('#email').val("");
$('#phone').val("");
$('#dayin').val("");
$('#dayout').val("");
$('#comments').val("");
$('#verify').val("");
$("#message").show().delay(5000).fadeOut('fast',
function(){
$("#slide_panel").slideToggle("slow");
});
}
);
});
return false;
});
});
我假設我需要做類似這樣的東西代碼:
if(data.match('success') != null);
在我contact.php形式....我有這個:
if (isset($_POST['verify'])) :
$posted_verify = $_POST['verify'];
$posted_verify = md5($posted_verify);
else :
$posted_verify = '';
endif;
// Important Variables
$session_verify = $_SESSION['verify'];
if (empty($session_verify)) $session_verify = $_COOKIE['verify'];
$error = '';
if(trim($name) == '') {
$error .= '<li>Your name is required.</li>';
}
if(trim($email) == '') {
$error .= '<li>Your e-mail address is required.</li>';
} elseif(!isEmail($email)) {
$error .= '<li>You have entered an invalid e-mail address.</li>';
}
if(trim($phone) == '') {
$error .= '<li>Your phone number is required.</li>';
} elseif(!is_numeric($phone)) {
$error .= '<li>Your phone number can only contain digits.</li>';
}
if(trim($comments) == '') {
$error .= '<li>You must enter a message to send.</li>';
}
if($session_verify != $posted_verify) {
$error .= '<li>The verification code you entered is incorrect.
</li>';
}
if($error != '') {
echo '<div class="error_message">Attention! Please correct the
errors below and try again.';
echo '<ul class="error_messages">' . $error . '</ul>';
echo '</div>';
} else {
if(get_magic_quotes_gpc()) { $comments = stripslashes($comments); }
我需要在這裏做什麼?或者我只需要編輯JavaScript文件?
嗨,檢查我的編輯以上我的問題...我已經添加了一些PHP代碼,可能需要編輯? – Reflex84
編輯我的答案以更好地代碼;) –