如何在表单处理(PHP)上访问下拉菜单中的值?

时间:2016-11-07 02:43:20

标签: php laravel-5

我很难填充这个国家的下拉列表。在控制器中提交和处理表单时,如何访问所选值?

<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;

1 个答案:

答案 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;?>">