{!! Form::hidden('reg',0) !!}
{!! Form::checkbox('reg',1,false) !!}
Aug 17, 2015
4
Level 2
Blade check box value
HI, have check box in Blade:
{!! Form::checkbox('reg',1,false) !!}
If box is checed,value is 1,that is ok,but when not checked,value is null.
IS there possibility to send value 0 to conttroller if box is uncheked?
P.S. I can manipulate with values in controller,of course, but just interesting is there away to do that directly in Blade...
Tnx, P
Level 56
When a box is not checked, it is not even sent through post data. A cool trick : put a hidden field with the same name before the checkbox.
<input type="hidden" name="reg" value="0">
{!! Form::checkbox('reg',1,false) !!}
So if the form is not checked, the hidden value is sent, if the box is checked it overrides the hidden value.
Otherwise, manage it at controller level :
$value = $request->get('reg', 0); // second parameter is default value
2 likes
Please or to participate in this conversation.