Reputation: 10095
My Controller Action Method is like below:
public function store(Request $request)
{
$IsActive = $request->input('IsActive');
echo $IsActive;
die();
}
My View is like below
{!! Form::open(array('method' => 'POST', 'action' => 'DepartmentController@store')) !!}
{!! Form::checkbox('IsActive', 0, null, array('class' => "flat")) !!}
{!! Form::submit('Save', array('class' => "btn btn-success"))!!}
{!! Form::close() !!}
Problem
On Form submit, I always get value = 0 for CheckBox. Am I missing something ?
Upvotes: 0
Views: 551
Reputation: 4020
You are getting 0
as value on form submit is because, you have explicitly declared value as 0
. Replace 0
with whatever value you want, and you will get the result as per your desire.
From the api source code:
/**
* Create a checkbox input field.
*
* @param string $name
* @param mixed $value
* @param bool $checked
* @param array $options
* @return string
*/
public function checkbox($name, $value = 1, $checked = null, $options = array())
{
return $this->checkable('checkbox', $name, $value, $checked, $options);
}
/**
* Create a checkable input field.
*
* @param string $type
* @param string $name
* @param mixed $value
* @param bool $checked
* @param array $options
*
* @return string
*/
protected function checkable($type, $name, $value, $checked, $options)
{
$checked = $this->getCheckedState($type, $name, $value, $checked);
if ($checked) {
$options['checked'] = 'checked';
}
return $this->input($type, $name, $value, $options);
}
Hope this helps you out.
Upvotes: 2