Laravel 集体复选框表单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40367482/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
laravel collective checkbox form
提问by Night5talker
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
我正在尝试在我的表单中实现复选框和 laravel 集合,但我在表单中只得到一个值,任何想法如何解决它
{!! 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?
标签也不起作用 - 对此也有想法吗?
采纳答案by raz
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.
只需将所有名称更改为 workday[] 即可。
{!! Form::checkbox('workday[]', 'monday') !!}
This will return all selected checkbox in an array.
这将返回数组中所有选定的复选框。
回答by Rimon Khan
Try this:
You used same name for every checkbox
when you checked
multiple checkbox
you only get the last value.
试试这个:checkbox
当你checked
多次使用相同的名称时,checkbox
你只会得到最后一个值。
{!! 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() !!}
回答by Mas Hary
You're using the same name (workday) for all your checkboxes. That's why it's only showing the last checkbox with that name
您对所有复选框使用相同的名称(工作日)。这就是为什么它只显示具有该名称的最后一个复选框
{{ Form::checkbox('workday[]', 'monday') }}