说我有复选框。每个都有一个值,当检查时进入数组。
<input type="checkbox" id="card_type1" name="card_type[]" value="easy" @if(old('card_type') != NULL && in_array('easy', old('card_type')) || old('foo', $parkingLot->m_plots_can_easycard) === '1') checked @endif>
<input type="checkbox" id="card_type2" name="card_type[]" value="icash" @if(old('card_type') != NULL && in_array('icash', old('card_type')) || old('foo', $parkingLot->m_plots_can_icash20) === '1') checked @endif>
<input type="checkbox" id="card_type3" name="card_type[]" value="ipass" @if(old('card_type') != NULL && in_array('ipass', old('card_type')) || old('foo', $parkingLot->m_plots_can_ipass) === '1') checked @endif>
第一次加载表单时,我想反映数据库的值。如果数据库中的值为&#39; 1&#39;,请选中该复选框。然后我修改复选框 - 检查一些并取消选中一些 - 然后提交表单并说表单提交失败。然后,我想通过检查每个值是否在旧复选框数组中来反映旧值,如果是,则检查复选框。
我的问题是old('value', 'default')
包含&#39;值&#39;和&#39;默认&#39;而且我无法使用单独的方法来确定是否应该选中该复选框。如果我这样做(如上所述),那么我就不能old('default')
- 并在那里进行单独检查 - 因为有一个参数使其成为old('value')
。
我不确定如何在我的情况下解决这个问题。任何指针或帮助将非常感激。我希望我能清楚地说明我的情况。
答案 0 :(得分:1)
您可以尝试以下
<input type="checkbox" id="card_type1" name="card_type[]" value="easy"
@if (in_array('easy', old('card_type', [$parkingLot->m_plots_can_easycard === '1' ? 'easy' : ''])))
checked
@endif>
<input type="checkbox" id="card_type2" name="card_type[]" value="icash"
@if (in_array('icash', old('card_type', [$parkingLot->m_plots_can_icash20 === '1' ? 'icash' : ''])))
checked
@endif>
<input type="checkbox" id="card_type3" name="card_type[]" value="ipass"
@if (in_array('ipass', old('card_type', [$parkingLot->m_plots_can_ipass === '1' ? 'ipass' : ''])))
checked
@endif>