2015-01-06 49 views
-1

我有一系列的複選框,當表單提交,並有一個錯誤(通過jQuery驗證),我需要這些複選框的狀態明顯持續存在,因此他們不必是重新進入:複選框狀態的形式不會堅持提交

<fieldset class="group"> 
     <label for="s_type" class="mandatory full-width <?=$errors['s_type']?>"><strong>Please indicate which you are applying for:</strong></label> 
     <span class="clear"></span> 
    </fieldset> 
    <fieldset class="group"> 
     <div class="field"> 
      <input <?php if($s_type == "Fund Scholarship") { echo 'checked';} ?> type="checkbox" value="Fund Scholarship" name="s_type[]" id="s_type_fund" validate="required:true"> 
      <label>Fund Scholarship</label><br/> 
      <input <?php if($s_type == "Foundation Scholarship") { echo 'checked';} ?> type="checkbox" value="Foundation Scholarship" name="s_type[]" id="s_type_foundation"> 
      <label>Foundation Scholarship</label><br /> 
      <input <?php if($s_type == "Memorial Scholarship") { echo 'checked';} ?> type="checkbox" value="Memorial Scholarship" name="s_type[]" id="s_type_mem"> 
      <label>Memorial Scholarship</label><br /> 
      <label class="error" for="s_type[]">This field is required</label></div> 
    </fieldset> 

出於某種原因,它的時候我選擇的選項中的一個既省了,如果我選擇2或3,它不救?不知道我很想念

編輯:哦,我應該指出,當選擇一個以上的,它只是失去了所有的狀態,即使當我選擇一個,同時也保留了正常。

編輯:我剛剛意識到,在代碼的頂部以下內容:

$s_type = implode("; ", $_POST['s_type']); 

我想這就是爲什麼$ S_TYPE ==「基金獎學金」據稱作品在另一個PHP頁面我使用模型這一個

+0

笑另一downvote的WOT? – makapaka

回答

0

$s_type永遠只能等於一兩件事的時間。

如果你想使用所有這些嘗試in_array()

<input <?php if(in_array("Foundation Scholarship",$_REQUEST['s_type'])) echo 'checked'; ?> type="checkbox" value="Foundation Scholarship" name="s_type[]" id="s_type_foundation"> 
+0

THX但是這給了我:警告:in_array()[function.in陣列]:用於在線458 類型=「複選框」值=「基金獎學金」名稱中/scholarships/business-form.php第二個參數錯誤的數據類型=「S_TYPE []」 ID =「s_type_fund」驗證=「要求:真正的」>基金獎學金...... 和複選框都搞砸 – makapaka