1 回答
TA贡献1824条经验 获得超6个赞
要获取下拉列表的值:您需要创建一个隐藏的输入字段,并且每次下拉列表的值发生变化时,您都需要更新它。
要获取POST中的数据controller:您需要在该控制器中创建一个控制器(显然)和一个函数。然后将该 URL 提供给表单操作属性。
我已经为你写了一个参考代码,并在评论中进行了必要的解释,看看它是否对你有帮助。
看法
<form method="post" action="<?php echo base_url('some_controller/some_function');?>" id="user-order-form">
<!-- give the action where controller name(some_controller) and function name(some_function) -->
<div class="users-order col-md-5">
<label class=""> <strong>ORDER BY </strong></label>
<div class="dropdown form-control" style="padding:0px; margin-left: 20px; margin-right:10px">
<button class="btn btn-default dropdown-toggle form-control" type="button" id="user-order-dropdown" name="user-order-dropdown" data-toggle="dropdown">
Surname
<span class="caret"></span>
</button>
<!-- make a hidden field, give it a default value(which is initially selected), give it a name(it will be used to get the post data)-->
<input type="hidden" name="dropdown" value="Surname"id="dropdown_input"/>
<ul class="dropdown-menu" aria-labelled-by="user-order-dropdown" id="capton">
<li><a href="#">Surname </a> </li>
<li><a href="#">First Name </a> </li>
<li><a href="#">Company Name </a> </li>
</ul>
</div>
<label class="radio-inline"><input type="radio" name="order-radio" checked>ASC</label>
<label class="radio-inline"><input type="radio" name="order-radio">DESC</label>
<button type="submit" class="btn" name="order-submit-btn" id="order-submit-btn">Order</button>
</div>
</form>
查询
$('.dropdown').each(function (key, dropdown) {
var $dropdown = $(dropdown);
$dropdown.find('.dropdown-menu a').on('click', function () {
$dropdown.find('button').text($(this).text()).append(' <span class="caret"></span>');
$('#dropdown_input').val($(this).text()); // change the value of hidden input field
});
});
控制器(Some_controller.php)
function some_function(){
$dropdown = $this->input->post('dropdown'); // get dropdown value
$order_radio = $this->input->post('order-radio'); // get radio value
/* Do whatever you want to with that data here(Eg - Save in DB) -- your logic */
}
- 1 回答
- 0 关注
- 86 浏览
添加回答
举报