2014-11-11 2 views
0

Laravel에서 유효성 검사에 실패하면 동일한 양식 페이지로 돌아갑니다. 체크 박스를 열거 나 채우지 않은 채 다시 채우는 방법은 무엇입니까?Laravel - 체크 박스를 체크 표시하거나 다시 체크 표시하지 않음

기본적으로 페이지에 처음 로딩 할 때 해제되어야합니다.

{{ Form::checkbox('custom_address', false, 
    Input::old('custom_address'), array('class' => 'test')); }} 
+1

'리디렉션을 반환 :: ('양식')로 -> withInput은(); 'http://laravel.com/docs/4.2/requests#old-input – nilobarp

+0

@NilotpalBarpujari 예 내가 이미 얻었다 참조 , return redirect :: to ('/ order/details') -> withErrors ($ validator) -> withInput (Input :: all())' –

답변

2

당신은 그렇지 않으면 Input 클래스는 항상 선택하지 않은/비어있을 것이다, 당신의 체크 박스의 값을 설정해야합니다.

체크 박스에 값 1을 지정하면 작동합니다.

{{ Form::checkbox('custom_address', 1, Input::old('custom_address'), array('class' => 'test')); }} 
-1

그냥 조건문을 사용하십시오.

@if(!empty(Input::old('custom_adress'))) 

{{ Form::checkbox('custom_address', true, 
Input::old('custom_address'), array('class' => 'test')); }} 

@else 

{{ Form::checkbox('custom_address', false, 
Input::old('custom_address'), array('class' => 'test')); }} 

@endif 
+0

이렇게 코드를 중복해서는 안됩니다. 그것은 유지 보수의 악몽으로 이어질 수 있습니다. 예를 들어 길가에 서 누군가가 코드를 변경했지만 두 곳에서 변경을 수행하지 않으면 어떻게됩니까? – thestepafter

+0

저의 의견으로는 판단에 _error가 있습니다. 조건부를 볼 때, 그리고 변경을하면 다른 모든 조건도 검사해야합니다. – itachi

관련 문제