我无法验证由姓名和电子邮件字段组成的简单表单,并且无法显示自定义错误消息。电子邮件错误消息似乎有效,但对于名称,我得到“此字段是必需的”。而不是我指定的那个。
表单 HTML:
你的名字:
<div class="right"><input type="text" id="alert_name" required/></div>
<p> </p>
<div class="left">Your Email:</div>
<div class="right"><input type="email" id="alert_email" required/></div>
<div class="clear:both;"> </div>
<p id="errors" style="clear: both; margin-top:15px; text-align: center; color: red;"> </p>
</form>
jQuery:
$( "#basic-modal-content" ).dialog({ autoOpen: false, width: 400, buttons: [ { text: "Ok", click: function() {
$("#email_alert_form").validate({
errorLabelContainer: '#errors',
messages: {
email: {
required: "Please enter an email address",
email: "Please enter a valid email address"
},
alert_name:
required: "Please enter your name"
}
}
});
if (!$('#email_alert_form').valid()){
} else {
var datastring = 'email_alert=' + 'true' + '&name='+ $('#alert_name').val() + '&email=' + $('#alert_email').val();
$.ajax({
type: "POST",
url: "process-contact.php",
data: datastring,
success: function(data) {
$( "#submitted_alert" ).dialog( "open" );
}
});
$( this ).dialog( "close" );
}
}
}
]
});
任何帮助将非常感激。