我想知道一些Laravel家伙是否可以提供帮助.
我有一个表单,其中我有2个单选按钮,当表单提交它通过验证器,如果验证器失败它返回到表单,填充输入的字段并显示错误消息.
我似乎无法为单选按钮执行此操作,如果在提交表单时单击一个并且出现错误,则会返回到填写完所有内容的表单,除了已选中的单选按钮现在为空.
我的单选按钮如下:
<input type="radio" name="genre" value="M" class="radio" id="male" />
<input type="radio" name="genre" value="F" class="radio" id="female" />
<span class="error">{{ $errors->first('genre') }}</span>
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.
Mel*_*vin 19
你可以尝试使用Laravel开箱即用的HTML收音机...... Laravel Docs Form复选框和Radio
使用刀片,
{{ Form::radio('genre', 'M', (Input::old('genre') == 'M'), array('id'=>'male', 'class'=>'radio')) }}
{{ Form::radio('genre', 'F', (Input::old('genre') == 'F'), array('id'=>'female', 'class'=>'radio')) }}
Run Code Online (Sandbox Code Playgroud)
或者只是php,
echo Form::radio('genre', 'M', (Input::old('genre') == 'M'), array('id'=>'male', 'class'=>'radio'));
echo Form::radio('genre', 'F', (Input::old('genre') == 'F'), array('id'=>'female', 'class'=>'radio'));
Run Code Online (Sandbox Code Playgroud)
Jas*_*nNZ 12
你可以这样做:
<input type="radio" name="genre" value="M" class="radio" id="male" <?php if(Input::old('genre')== "M") { echo 'checked="checked"'; } ?> >
<input type="radio" name="genre" value="F" class="radio" id="female" <?php if(Input::old('genre')== "F") { echo 'checked="checked"; } ?> >
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16702 次 |
| 最近记录: |