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 關注
- 103 瀏覽
添加回答
舉報