我很难填充这个国家的下拉列表。在控制器中提交和处理表单时,如何访问所选值?
<div class="form-group form-group-default">
<label class="">Country</label>
<select class="full-width select2-offscreen" data-placeholder="Select Country" data-init-plugin="select2" tabindex="-1" title="">
<?php if(isset($country)&&!empty($country)) {?>
<?php foreach($country as $count_id): ?>
<option value="<?php $count_id -> id;?>" name="country">
<?php echo $count_id -> name;?> </option>
</optgroup>
<?php endforeach; ?>
<?php } ?>
</optgroup>
</select>
</div>
控制器:
$profile -> country_id = $request -> country;
答案 0 :(得分:2)
name属性应该在select元素上而不在选项元素
上添加姓名=&#34;国家&#34;属性选择
<select name="country" class="full-width select2-offscreen" data-placeholder="Select Country" data-init-plugin="select2" tabindex="-1" title="">
并从选项
中删除名称属性<option value="<?php $count_id -> id;?>">