我正在使用 Laravel 5.3
,这是下面的表单演示:
<div class="container">
<form>
<div class="form-group row">
<label for="name" class="col-sm-2 col-form-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="name" name="name" value="{{ old('name', $student->name)}}">
</div>
</div>
<fieldset class="form-group row">
<legend class="col-form-legend col-sm-2">Gender</legend>
<div class="col-sm-10">
<div class="form-check">
<label class="form-check-label">
<input class="form-check-input" type="radio" name="gender" value="1" @if(old('gender',$student->gender)=="1") checked @endif>
Male
</label>
</div>
<div class="form-check">
<label class="form-check-label">
<input class="form-check-input" type="radio" name="gender" value="2" @if(old('gender',$student->gender)=="2") checked @endif>
Female
</label>
</div>
</div>
</fieldset>
<div class="form-group row">
<label class="col-sm-2">Hobbies</label>
<div class="col-sm-10">
<div class="form-check">
<label class="form-check-inline">
<input class="form-check-input" type="checkbox" name="hobby[]" value="1" @if(...) checked @endif> football
</label>
<label class="form-check-inline">
<input class="form-check-input" type="checkbox" name="hobby[]" value="2" @if(...) checked @endif> basketball
</label>
<label class="form-check-inline">
<input class="form-check-input" type="checkbox" name="hobby[]" value="3" @if(...) checked @endif> swimming
</label>
</div>
</div>
</div>
<div class="form-group row">
<div class="offset-sm-2 col-sm-10">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
</div>
我的问题是:
我可以input type="text"
像这样显示旧数据:
<input type="text" class="form-control" id="name" name="name" value="{{ old('name', $student->name)}}">
我可以input type="radio"
像这样显示旧数据:
<input class="form-check-input" type="radio" name="gender" value="1" @if(old('gender',$student->gender)=="1") checked @endif>
但我不知道如何显示旧数据input type="checkbox"
:
<input class="form-check-input" type="checkbox" name="hobby[]" value="3" @if(...) checked @endif>
怎么做?
in_array()
方法 —— 布莱克 2016 年 9 月 15 日 23:21