我很难填充这个国家的下拉列表。当表单在控制器中提交和处理时,如何访问选中的值?
<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;
name属性应该在select元素上而不是option元素上
添加name="country"属性来选择
<select name="country" class="full-width select2-offscreen" data-placeholder="Select Country" data-init-plugin="select2" tabindex="-1" title="">
并从选项
中删除name属性<option value="<?php $count_id -> id;?>">