简体   繁体   English

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

[英]How can the value from a drop-down menu be accessed on form processing (PHP)?

I am having a hard time populating this country dropdown. 我在填充此国家/地区下拉菜单时遇到了困难。 How can the selected value be accessed when the form is submitted and processed in the controller? 在控制器中提交和处理表单时,如何访问所选值?

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

Controller: 控制器:

$profile -> country_id = $request -> country;

The name attribute should be on select element not on option element 名称属性应位于选择元素上,而不应位于选项元素上

Add name="country" attribute to select 添加name =“ country”属性以选择

<select name="country" class="full-width select2-offscreen" data-placeholder="Select Country" data-init-plugin="select2" tabindex="-1" title="">

And remove name attribute from option 并从选项中删除名称属性

<option value="<?php $count_id -> id;?>">

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

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