課程
/后端開發
/PHP
/輕松學會Laravel-表單篇
單選框的數據保持怎么做?單選框不選中的話舊數據數組中沒有這個下標,用@if判斷會報錯
2017-07-06
源自:輕松學會Laravel-表單篇 2-5
正在回答
把create.blade.php里面性別那段div換成這樣就好了
<div class="col-sm-5"> ? ?@foreach($student->getSex() as $ind=>$val) ? ?<label class="radio-inline"> ? ? ? ?<input type="radio" name='Student[sex]' ? ? ? ? ? ? ? value="{{ $ind }}" {{ old('Student')['sex']==$ind ? 'checked' : '' }}> {{ $val }} ? ?</label> ? @endforeach</div>
大爆炸a
您好,我也出現這個問題。數據保持。單選框,如果第一次不選中性別,下一次提交則出現找不到sex。謝謝
慕哥5535555
依然1233682660 提問者 回復 慕哥5535555
_晨曦oc 回復 依然1233682660 提問者
已解決!
你這個判斷出錯是查不到這個下標,也就是你的數組名字有誤或者下標名字不對。注意大小寫
依然1233682660 提問者
<div class="col-sm-5"> ? ?@foreach($student->sex() as $key => $val) ? ? ? ?<label class="radio-inline"> ? ? ? ? ? ?<input type="radio" name='Student[sex]' value="{{ $key }}" ? ? ? ? ? ? ? ? ? ?{{ $key == $student->sex ? "checked='checked'" : '' }}> {{ $val }} ? ? ? ?</label> ? ?@endforeach</div>
Vim_
舉報
Laravel框架是世界上最流行的PHP框架,沒有之一
1 回答頁面提交后保存老數據 單選框如何保存呢··
1 回答如果是大批量的表單,什么類型都有的話,數據保持怎么做?
4 回答validate的數據保持
1 回答數據的保持問題
1 回答菜單選中原理
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2017-08-29
把create.blade.php里面性別那段div換成這樣就好了
<div class="col-sm-5">
? ?@foreach($student->getSex() as $ind=>$val)
? ?<label class="radio-inline">
? ? ? ?<input type="radio" name='Student[sex]'
? ? ? ? ? ? ? value="{{ $ind }}" {{ old('Student')['sex']==$ind ? 'checked' : '' }}> {{ $val }}
? ?</label>
? @endforeach
</div>
2017-08-13
您好,我也出現這個問題。數據保持。單選框,如果第一次不選中性別,下一次提交則出現找不到sex。謝謝
2017-07-08
已解決!
2017-07-07
你這個判斷出錯是查不到這個下標,也就是你的數組名字有誤或者下標名字不對。注意大小寫
2017-07-07
<div class="col-sm-5">
? ?@foreach($student->sex() as $key => $val)
? ? ? ?<label class="radio-inline">
? ? ? ? ? ?<input type="radio" name='Student[sex]' value="{{ $key }}"
? ? ? ? ? ? ? ? ? ?{{ $key == $student->sex ? "checked='checked'" : '' }}> {{ $val }}
? ? ? ?</label>
? ?@endforeach
</div>