0

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 ?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.