这是我用于表单的代码,也许它可以提供帮助。
<script type="text/javascript">
$('document').ready(function(){
$('#form').validate({
ignore: ".ignore",
rules:{
"name":{
required:true,
maxlength:40
},
"phone":{
required:true,
},
"email":{
required:true,
email:true,
maxlength:100
},
hiddenRecaptcha: {
required: function () {
if (grecaptcha.getResponse() == '') {
return true;
} else {
return false;
}}},
"message":{
required:true
}},
messages:{
"name":{
required:"Please tell us your name"
},
"phone":{
required:"Please tell us your phone number"
},
"email":{
required:"How can we send you information? We promise, we will never give away your email!",
email:"Please enter a valid email address"
},
"hiddenRecaptcha":{
required:"Please check the box to show us you are human"
},
"message":{
required:"Please tell us what we can tell you about this vessel"
}},
submitHandler: function(form){
$(form).ajaxSubmit({
target: '#preview',
success: function() {
$('#formbox').slideUp('fast');
}
});
}
})
});
</script>
<div id="preview"></div>
<div id="formbox">
<div>
<p class="contactform">Contact Form:</p>
<form name="form" id="form" action="http://www.yourdomaingoeshere.com/submit.php" method="post">
<div class="g-recaptcha" data-sitekey="your site key goes here" style="padding-bottom: 20px!important;"></div>
<input type="hidden" class="hiddenRecaptcha required" name="hiddenRecaptcha" id="hiddenRecaptcha">
<ul id="ngothastyle3" class="mylist">
<li class="mylist">
<input type="text" placeholder="your name" name="name" class="" />
</li>
<li class="mylist">
<input type="text" placeholder="phone number" name="phone" class="" />
</li>
<li class="mylist">
<input type="text" placeholder="email" name="email" class="" />
</li>
<li class="mylist">
<textarea name="message" placeholder="comments" rows="5" cols="45" class=""></textarea>
</li>
</div>
<div style="float: right;">
<li class="mylist" style="list-style: none;">
<input type="submit" value="Send"/>
</li>
</div>
</ul>
</form>