Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel collective checkbox form

I'm trying to implement checkbox and laravel collective in my form but I get only single value in form, any ideas how to fix it

{!! Form::open(array('action'=>'UserController@updateInfo','method'=>'post')) !!}
 Workdays:
<br>
{!! Form::label('monday', 'Monday') !!}
{!! Form::checkbox('workday', 'monday') !!}
<br>
{!! Form::label('tuesday', 'Tuesday') !!}
{!! Form::checkbox('workday', 'tuesday') !!}
<br>
{!! Form::label('wednesday', 'Wednesday') !!}
{!! Form::checkbox('workday', 'wednesday') !!}
<br>
{!! Form::label('thursday', 'Thursday') !!}
{!! Form::checkbox('workday', 'thursday') !!}
<br>
{!! Form::label('friday', 'Friday') !!}
{!! Form::checkbox('workday', 'friday') !!}
<br>
{!! Form::label('saturday', 'Saturday') !!}
{!! Form::checkbox('workday', 'saturday') !!}
<br>
{!! Form::label('sunday', 'Sunday') !!}
{!! Form::checkbox('workday', 'sunday') !!}
<br>
{!! Form::submit('Save', $attributes = ['class'=>'button']) !!}
{!! Form::close() !!}

when I print my request i only get single output (eg. selected monday friday I get only friday when request is processed)

also labels not working - ideas on that too?

like image 688
Night5talker Avatar asked Nov 01 '16 19:11

Night5talker


2 Answers

You're using the same name (workday) for all your checkboxes. That's why it's only showing the last checkbox with that name

Just change all names to workday[] instead.

{!! Form::checkbox('workday[]', 'monday') !!}

This will return all selected checkbox in an array.

like image 59
raz Avatar answered Nov 20 '22 02:11

raz


Try this: You used same name for every checkbox when you checked multiple checkbox you only get the last value.

{!! Form::open(array('action'=>'UserController@updateInfo','method'=>'post')) !!}
 Workdays:
<br>
{!! Form::label('monday', 'Monday') !!}
{!! Form::checkbox('workday[]', 'monday') !!}
<br>
{!! Form::label('tuesday', 'Tuesday') !!}
{!! Form::checkbox('workday[]', 'tuesday') !!}
<br>
{!! Form::label('wednesday', 'Wednesday') !!}
{!! Form::checkbox('workday[]', 'wednesday') !!}
<br>
{!! Form::label('thursday', 'Thursday') !!}
{!! Form::checkbox('workday[]', 'thursday') !!}
<br>
{!! Form::label('friday', 'Friday') !!}
{!! Form::checkbox('workday[]', 'friday') !!}
<br>
{!! Form::label('saturday', 'Saturday') !!}
{!! Form::checkbox('workday[]', 'saturday') !!}
<br>
{!! Form::label('sunday', 'Sunday') !!}
{!! Form::checkbox('workday[]', 'sunday') !!}
<br>
{!! Form::submit('Save', $attributes = ['class'=>'button']) !!}
{!! Form::close() !!}
like image 30
Rimon Khan Avatar answered Nov 20 '22 02:11

Rimon Khan