2015-01-06 2 views
-1

양식이 제출되고 오류 (jquery 유효성 검사를 통해)가있을 때 일련의 체크 박스가 있는데, 분명히 유지해야하는 확인란의 상태가 필요합니다. 다시 입력 : I이 옵션 중 하나를 선택한 경우 내가 2 또는 3, 그것은 저장하지 않습니다를 선택하면 어떤 이유체크 박스 상태가 양식 제출시 지속되지 않음

<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> 

, 그에만 저장? 내가 무엇을 놓치고 있는지 잘 모르겠다.

편집 : 오, 내가 하나 이상을 선택하면 그 상태를 잃어 버린다.

편집 : $ s_type == "기금 장학금"내가 모델 가정으로 다른 PHP 페이지에서 작동 사용하고 있는데 왜

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

나는 그게 가정 : 난 그냥 코드의 맨 위에 다음 것을 깨달았다 이 하나

+0

를 시도? – makapaka

답변

0

$s_type 한 번에 하나만 같을 수 있습니다. 당신이 사용하려는 경우

그들 모두는 롤 WOT에 대한 또 다른 downvote을 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- 배열] : /scholarships/business-form.php의 두 번째 인수에 잘못된 데이터 유형이 있습니다. 458 type = "checkbox"value = "Fund Scholarship"name = "s_type []"id = "s_type_fund"validate = "required : true"> 기금 장학금 ... 그리고 모든 확인란이 엉망입니다. – makapaka

관련 문제