2013-06-25 46 views
2

我有一個簡單的HTML5表單。但是當我執行代碼驗證程序(http://validator.w3.org/check)時,出現多個錯誤帶標籤的HTML5驗證表單

標籤元素的for屬性必須引用表單控件。這個錯誤是什麼意思?它是指向該行

<label id="name0" for="Name" style="width: 180px;">Name</label> 

這是我目前的形式

<div id="contact-add" title="Add New Contact" style="display: none;"> 

     <div id="response-add"></div> 
     <form method="post" id="add-form"> 

     <div class="label-input"> 
      <label id="name0" for="Name" style="width: 180px;">Name</label> 
      <input type="text" id="fullname0" value="" name="name" placeholder="Enter full name..." /> 
      <input type="hidden" name="add_account_id" id="add_account_id" value="<?php echo $add_account_id; ?>" /> 

     </div> 

     <div class="label-input"> 
      <label id="title0" for="title" style="width: 180px;">Title (Optional)</label> 
      <input type="text" value="" name="title" placeholder="Enter title here..." /> 
     </div>  

     <div class="label-input"> 
      <label id="email0" for="email" style="width: 180px;">Email (Optional)</label> 
      <input type="text" value="" id="email" name="email" placeholder="Enter email address..." /> 
     </div> 


     <div class="label-input"> 
      <label id="phone0" for="phone" style="width: 180px;">Direct Number (Optional)</label> 
      <input type="text" value="" id="phone_number" name="phone_number" placeholder="Enter direct number..." /> 
     </div>   
     <div class="label-input"> 
      <label id="extention0" for="extention" style="width: 180px;">Extention (Optional)</label> 
      <input type="text" value="" id="phone_ext" name="phone_ext" placeholder="Enter extention number..." /> 
     </div> 

     <div class="label-input"> 
      <label id="shift0" for="shift" style="width: 180px;">Work Shift</label> 
      <?php echo generateWorkShiftMenu($db, 'work_shift', 'Day'); ?> 
     </div> 


     </form> 
</div> 
+2

可能重複:http://stackoverflow.com/questions/5137628/html5-validation-form-tag – showdev

回答

1

標籤的for屬性必須是一個表單控件的ID。即

<label id="name0" for="fullname0" style="width: 180px;">Name</label> 
<input type="text" id="fullname0" value="" name="name" placeholder="Enter full name..." /> 
+0

謝謝。這是問題所在。 – Mike