我有一個來自jQuery UI的模式對話框,當我按下按鈕時出現。下面是關於模態對話框jQuery代碼:使用jQuery驗證電子郵件
$('#eb1').click(function(){
$('#emailPost').submit();
$("#emailModal").dialog('close');
});
$('#eb2').click(function(){
$('#emailPost2').submit();
$("#emailModal").validate({
rules: {
emailAddress: {
required: true,
email: true
}
}
}).showErrors({"error": "Invalid Email!"});
$("#emailModal").dialog('close');
});
下面是顯示所有這一切的PHP:
echo "<form action='php/emailPost.php' method='POST' class='inline' id='emailPost'>";
echo "<input type='hidden' value='" . $_SESSION["email"] . "' name='emailAddress'>";
echo "<input type='button' value='Email To Me' id='eb1'/>";
echo "<input type='hidden' name='passedCoupID' value='" . $coupID . "'/>";
echo "</form>";
echo "<h3>Or</h3>";
echo "<form action='php/emailPost.php' method='POST' class='inline' id='emailPost2'>";
echo "<label name='error'></label>";
echo "<input type='text' value='Enter an Email' class='required email' name='emailAddress' style='display: inline-block;'>";
echo "<input type='button' value='Email' id='eb2'/>";
echo "<input type='hidden' name='passedCoupID' value='" . $coupID . "'/>";
echo "</form>";
我知道的按鈕做工精細,以及他們提交完美,但後者的提交不分的驗證結果。我很新的jQuery,我如何使它顯示一個錯誤,如果無效,不提交,除非電子郵件有效?