Opencart 获取控制器的 select 值以进行过滤

Opencart get select value to controller for filter

我有一个名为 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>

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

$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' 作为 selected customer_id。我的意思是将 select 值传递给控制器​​页面

在视图页面中尝试此代码

<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."'");