artisticre's avatar

Checkbox question

I have a checkbox that works like I want to if it is checked but if its not checked I get Undefined index: financialsupport

Checkbox

<input class="financialsupport" type="checkbox" name="financialsupport" value="I Require Financial Support"/>
        'financialsupport' => ['nullable'],
         $team->financialsupport = $data['financialsupport'];

0 likes
2 replies
guybrush_threepwood's avatar
Level 33

If a checkbox is unchecked when its form is submitted, there is no value submitted to the server to represent its unchecked state (e.g. value=unchecked); the value is not submitted to the server at all.

You should use the has method to determine if a value is present on the request. The has method returns true if the value is present on the request.

Try something like:

$team->financialsupport = $request->has('financialsupport');

Please or to participate in this conversation.