可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I have created radio button fields as follows
EDIT: I have changed form as suggested in comments
<div class="form-group">
{!! Form::label('is_kids_friendly','Kids Friendly:') !!}
{!! Form::radio('kidsfriendly', 'true', null),' ', 'Yes' !!}
{!! Form::radio('kidsfriendly', 'false', null),' ','No' !!}
</div>
<div class="form-group">
{!! Form::label('is_kids_only','Kids Only:') !!}
{!! Form::radio('kidsonly', 'true', null),' ', 'Yes' !!}
{!! Form::radio('kidsonly', 'false', null),' ','No' !!}
</div>
<div class="form-group">
{!! Form::label('sineor_citizan_friendly','Sineor Citizan Friendly:') !!}
{!! Form::radio('seniorcitizen', 'true', null),' ', 'Yes' !!}
{!! Form::radio('seniorcitizen', 'false', null),' ','No' !!}
</div>
As this is radio button field, i have used boolean
in database.
Each time, i fill in details, It takes 0
. Also, i can select multiple radio button, thats should not happen.
Am i doing something wrong?
回答1:
You should do following changes then your controller query will work as you want!
<div class="form-group">
{!! Form::label('is_kids_friendly','Kids Friendly:') !!}
{!! Form::radio('is_kids_friendly', true, null),' ', 'Yes' !!}
{!! Form::radio('is_kids_friendly', false, null),' ','No' !!}
</div>
<div class="form-group">
{!! Form::label('is_kids_only','Kids Only:') !!}
{!! Form::radio('is_kids_only', true, null),' ', 'Yes' !!}
{!! Form::radio('is_kids_only', false, null),' ','No' !!}
</div>
<div class="form-group">
{!! Form::label('sineor_citizan_friendly','Sineor Citizan Friendly:') !!}
{!! Form::radio('sineor_citizan_friendly', true, null),' ', 'Yes' !!}
{!! Form::radio('sineor_citizan_friendly', false, null),' ','No' !!}
</div>
回答2:
The name
should be same with different value
s. Try with -
{!! Form::label('is_kids_friendly','Kids Friendly:') !!}
{!! Form::radio('is_kids_friendly', 'yes', true),' ', 'Yes' !!}
{!! Form::radio('is_kids_friendly', 'no'),' ','No' !!}
The arguments are - radio('name of field', 'value', 'checked or not')
回答3:
{!! Form::label('is_kids_friendly','Kids Friendly:') !!}
{!! Form::radio('value', 'yes', null),' ', 'Yes' !!}
{!! Form::radio('value', 'no', null),' ','No' !!}
Try this:
first parameter is name of radio button , second parameter is value, third is default checked
回答4:
You are passing $request->all() directly to the create method, in which case your HTML field's name should be same as the column names in your DB
<div class="form-group">
{!! Form::label('is_kids_friendly','Kids Friendly:') !!}
{!! Form::radio('is_kids_friendly', 'true', null),' ', 'Yes' !!}
{!! Form::radio('is_kids_friendly', 'false', null),' ','No' !!}
</div>
<div class="form-group">
{!! Form::label('is_kids_only','Kids Only:') !!}
{!! Form::radio('is_kids_only', 'true', null),' ', 'Yes' !!}
{!! Form::radio('is_kids_only', 'false', null),' ','No' !!}
</div>
<div class="form-group">
{!! Form::label('senior_citizen_friendly','Sineor Citizan Friendly:') !!}
{!! Form::radio('senior_citizen_friendly', 'true', null),' ', 'Yes' !!}
{!! Form::radio('senior_citizen_friendly', 'false', null),' ','No' !!}
</div>