Opencart获取选择值到控制器进行过滤

时间:2017-04-03 12:27:58

标签: select opencart

我有一个名为 no.tpl 的页面,在此页面中显示select dropdown

中的客户名称

这是代码: 的 no.tpl

<select name="customer_id" id="customer" style="width: 325px;margin-bottom:10px" class="form-control">
    <?php foreach($customerData as $customer){ ?>
        <option value=<?php echo $customer['customer_id']?>><?php echo $customer['customer_name']?></option>
    <?php }?>
</select>

在控制器页面中,我必须过滤选定的客户列表

$queryCustomer = $this->db->query("select customer_id, concat(firstname, ' ',lastname) as name, email from " . DB_PREFIX . "customer where customer_id='6'");
             $selectedCustomer = $queryCustomer->row;
             $selectedCustomerId = $selectedCustomer['customer_id'];
             $selectedCustomerName = $selectedCustomer['name'];
             $selectedCustomerEmail = $selectedCustomer['email'];

我希望customer_id='6'成为选定的customer_id。我的意思是将选择值传递给控制器​​页面

1 个答案:

答案 0 :(得分:1)

在视图页

中试用此代码
<select name="customer_id" id="input-sales-person" style="width: 325px;margin-bottom:10px" class="form-control">
    <?php foreach($customerData as $customer){ ?>
        <option id="temp" value=<?php echo $customer['customer_id']?>><?php echo $customer['customer_name']?></option>
    <?php }?>
</select>

 <input type="submit" id="noOrder" Onclick="return ConfirmDelete();" value="Submit" class="btn btn-primary">

使用以下脚本

<script type="text/javascript">
    $('#noOrder').on('click', function() {
        var temp1=$( "#input-sales-person option:selected" ).val();
        var temp2=$( "#input-sales-person option:selected" ).text();
        document.cookie = "selectedCustomerId=" +temp1;
        document.cookie = "selectedCustomerName=" +temp2;
        location="index.php?route=sale/no";
    });
</script>

在控制器中将customer_id传递为$selectedCustomerId=$_COOKIE['selectedCustomerId'];

$selectedCustomerId=$_COOKIE['selectedCustomerId']; /*customer_id=6*/

$queryCustomer = $this->db->query("select customer_id, concat(firstname, ' ',lastname) as name, email from " . DB_PREFIX . "customer where customer_id='".$selectedCustomerId."'");
相关问题