【发布时间】:2015-05-13 14:45:56
【问题描述】:
如何在 Laravel 5 中正确取回旧的单选按钮值?因为使用 old('radiobutton1');返回一个包含“on”的字符串,它在第一次失败时是正确的并返回正确的按钮,但是如果您选择第二个单选按钮(在这种情况下只有两个选项),它将返回两个旧的“on”字符串('radiobutton1') 和旧的('radiobutton2')
代码示例:
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary @if(old('radiobutton1') == "on") active @endif">
<input type="radio" name="radiobutton1" id="radiobutton1" @if(old('radiobutton1') == "on") checked @endif autocomplete="off"> Option1
</label>
<label class="btn btn-primary @if(old('radiobutton2') == "on") active @endif">
<input type="radio" name="radiobutton2" id="radiobutton2" @if(old('radiobutton2') == "on") checked @endif autocomplete="off"> Option2
</label>
</div>
附:
单选按钮的样式使用 Twitter Bootstraps 的 JavaScript 单选按钮,如果有的话。
【问题讨论】:
-
您的单选按钮实际上应该具有相同的
name和不同的值。如果它们应该单独工作,您应该使用复选框。
标签: javascript php twitter-bootstrap laravel laravel-5