【发布时间】:2014-08-13 09:20:34
【问题描述】:
我有一个带有多个属性的复选框循环。一个内容可能有多个属性,因此用户可以检查多个属性。
如果此表单中出现某些验证错误,我需要预先获取已检查的属性。
@foreach($attributes as $entry)
<div class="check-line">
<input type="checkbox" id="cat4" class='icheck-me'
name="attribute[<?php echo $entry->id; ?>]"
data-skin="square"
data-color="blue"
value="{{$entry->id}}"
<?php
if(Input::old('attribute['.$entry->id.']')== $entry->id) {
echo 'checked="checked"';
}
?>
/>
<label class='inline' for="cat4">
<strong>{{$entry->name}}</strong>
</label>
</div>
@endforeach
我在上面试过但没有运气..有什么想法吗?
【问题讨论】:
-
在我看来您需要在数组中搜索:
<input type="checkbox" name="attribute[<?php echo $ii; ?>]" value="<?php echo $entry->id; ?>" <?php if (in_array($entry->id, Input::old('attribute'))) echo 'checked'; ?>>对吗?
标签: php validation checkbox laravel laravel-4