2011-08-01 22 views
1

我有一個表單,我正在驗證使用jQuery的驗證插件。我試圖做的是將錯誤顯示在一個單獨的稱爲「錯誤」的div可以讓任何人幫助我嗎?即時通訊使用jQuery驗證如何在單獨區域顯示錯誤

形式的代碼是在這裏:

<form name="contactform" id="contactform" method="post" action="/contactform/send_form_email.php"> 

      <label for="your_name">YOUR NAME</label> 
      <input type="text" name="your_name" id="your_name" class="fulltext"/> 

      <label for="type">TYPE OF EVENT</label> 
      <input type="text" name="type" id="type" class="fulltext"/> 

      <label for="guests">GUESTS</label> 
      <input type="text" name="guests" id="guests" class="shorttext"/> 

      <label for="date">DATE</label> 
      <input type="text" name="date" id="date" class="shorttext"/> 

      <label for="phone">PHONE</label> 
      <input type="text" name="phone" id="phone" class="shorttext"/> 

      <label for="email">ENTER EMAIL ADDRESS</label> 
      <input type="text" value="ENTER EMAIL ADDRESS" name="email" id="email" class="fulltext"/> 
      <button type="submit" value="submit">go</button> 
      </form> 

和JavaScript是在這裏:

rules: { 
    email: { required: true, email: true, maxlength: 50 }, 
    honeypot: { maxlength: 0 } 
    } 
    }); 

任何幫助,這將不勝感激。

謝謝。這裏提到的http://jquery.bassistance.de

+0

的JavaScript代碼是不完整的。你的頭部被切斷。 – reporter

+0

你使用了哪種jQuery驗證? http://www.google.fr/search?sourceid=chrome&ie=UTF-8&q=jquery+validation ^^ – Awea

+0

我使用了http://bassistance.de/jquery-plugins/jquery-plugin-validation/ – macroj

回答

1

驗證插件有兩個屬性errorContainererrorPlacement,你可以網頁上的其他一些地方使用到的地方/顯示錯誤。這裏是一個演示http://jquery.bassistance.de/validate/demo/custom-methods-demo.html。查看來源。如果您使用的是相同的插件,我相信您使用的插件應該會有所幫助。提交處理程序需要實際處理提交表單。請注意以下代碼

$("#myform").validate({ 
submitHandler: function(form) { 
    // some other code 
    // maybe disabling submit button 
    // then: 
    $(form).submit();//notice how form object is used, not the **id** of form is used here 
    //^ if you dont take care, you will end up in too much recursion error 
} 
}); 

請閱讀此文檔http://docs.jquery.com/Plugins/Validation瞭解更多信息。

+0

只有一個更多的問題我的表單仍然似乎提交即使這個代碼如果我輸入一個電子郵件地址,它應該要求名稱和電話我失蹤了什麼? $(document.ready)(function(){(「a.example1」)。fancybox(); $(「#contactform」)。validate({errorLabelContainer:$(「#contactform div.error」) , rules:{ your_name:{required:true,maxlength:50}, phone:{required:true,maxlength:50}, 電子郵件:{required:true,email:true,maxlength:50}, honeypot :{maxlength:0} } }); }); – macroj

+0

你需要一個'submitHandler'。 – Kumar

+0

對不起,我不明白你可以請擴展一下嗎? – macroj

1

可以使用errorLabelContainer選項:

$("#contactform").validate({ 
    rules: { 
     email: { required: true, email: true, maxlength: 50 }, 
     honeypot: { maxlength: 0 } 
    }, 
    errorLabelContainer: "#error", 
    wrapper: "<div>" 
}); 
相關問題