简体   繁体   English

重新填充选择字段中的值

[英]Repopulate values in select field

I want to repopulate the old value after validation.I have tried many options and I am not getting. 我想在验证后重新填充旧值。我尝试了许多选项,但没有得到。

Here is my code 这是我的代码

select name="Skills[]" class="form-control select2" multiple="multiple" id ="Skills"
@foreach($skills as $skill)
option value="{{$skill->skill_id}}" >{{$skill->skill_name}}</option>            
@endforeach         
/select

correct me if I'm wrong but what you mean by repopulate the old value is to show as selected the option chosen by the user after validation right? 纠正我,如果我错了,但是重新填充旧值的意思是将验证正确后用户选择的选项显示为选中状态?

if so then you can try after redirecting to a View the following: 如果是这样,那么您可以在重定向到View之后尝试以下操作:

    <?php $i=1; ?>
    <select name="Skills[]" class="form-control select2" multiple="multiple" id ="Skills">
      @foreach($skills as $skill)
        <option value="{{$skill->skill_id}}" @if($skill->skill_id==$i++){'selected="selected"'}@endif>{{$skill->skill_name}}</option>
      @endforeach
    </select>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM