如何使用PHP / Codeigniter从单个窗体中检索多个文本框值? [英] How to retrieve multiple text box values from single form using PHP/Codeigniter?

查看:102
本文介绍了如何使用PHP / Codeigniter从单个窗体中检索多个文本框值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在电子商务网站上工作。我有一个产品页面,我有单一的形式,使用按钮同时添加多个产品数量。
在我的产品页面上,在我的单一形式中,我使用循环将单个产品值发送到下一页:

I am working on an eCommerce website.I have a product page where i have single form to add multiple product quantities at the same time using the button . On my products page,within my single form i am sending individual product values to next page like these using the loop:

<?
$query_data=$this->db->get('products');
foreach($query_data->result() as $product)
 {
?>
  <input name="productname[]" value="<?=$product->Name?>" type="hidden" />
 <input type = "hidden" id = "product_id" name = "product_id[]" value = "<?=$product->Code?>" />
  <input name="num_pallets[]" id="num_pallets" value="<?=$pallet?>" type="hidden" />
 <input type = "hidden" id = "num_packs" name = "num_packs[]" value = "<?=$packet?>" />
 <input type="text" name="quantity[]" id="quantity" size="2" />
<input type = "hidden" id = "product_price" name = "product_price" value = "<?=$number?>" />    
<? 
 }
 ?>

其中:

数量字段是客户将订购的产品的数量。

1) the "quantity" field is the quantity of the product a customer will order.

2)num_pallets字段是产品在数据库中具有的产品的货盘数量。

2) the "num_pallets" field is the pallet quantity of the product a product has in the database.

3)num_packs字段是产品在数据库中具有的产品的包装数量。

3) the "num_packs" field is the pack quantity of the product a product has in the database.

现在,我想检索购物车页面上的相应值,以便我可以相应地执行计算。

Now,i want to retrieve the corresponding values on shopping cart page so that i could perform calculations accordingly.

我的另一个问题是,当我提交我的表格,它提交所有的价值包括我不输入数量的文本框中的产品的价值。

The other problem i have is that when i submit my form,it submits all the values INCLUDING THE products' values of those I dont enter quantity in the text boxes.

我的问题:

如何在我的网页上循环产品(我在文本框中输入数量给我相应的有序产品的价值只是ie如果我填写数量文本框的产品(11760),然后我想处理值11760,而不是其他产品。

How can i loop through the products (I enter the "quantity" in text boxes) on my page so that it could give me the corresponding values of the ordered products ONLY i.e if i fill in the quantity text box of product(11760) then i want to process values of 11760 ,not other products.

如何检索1个或多个有序产品的相应值?

How can i retrieve the corresponding values of 1 or more ordered product only ??Thanks

推荐答案

这里是解决方案。我已经工作了,测试和发现,为了保持相应的索引与单个产品,我需要传递产品代码的多维数组的形式,像这样:

Here is the solution.I have worked it out ,tested and found that in order to keep corresponding indexes together with the individual products,I will need to pass the product code in the form of multidimensional array like this:

  <?
   if (isset($_POST['quantity']) && is_array($_POST['quantity']))  
  {

    $field_array = array();
     foreach($_POST['quantity'] AS $itemID => $value) 
     {  
            if ($_POST['quantity'][$itemID]>0)
          { 

         if (isset($_POST['product_id'][$itemID])&& (isset($_POST['product_price'][$itemID])) && (isset($_POST['counter'][$itemID]))&& (isset( $_POST['quantity'][$itemID])))

              {

                $productid=$_POST['product_id'][$itemID];
                $this->load->model('m_shopping_cart');
           $pricehead=($_POST['quantity'][$itemID])*($_POST['product_price'][$itemID]);
           $this->m_shopping_cart->add_to_cart($_POST['product_id'][$itemID],$_POST['product_price'][$itemID],$_POST['quantity'][$itemID],$_SESSION['cart_id'],$pricehead,false,false,false);
               }
         } 
      }

}
?>

这篇关于如何使用PHP / Codeigniter从单个窗体中检索多个文本框值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆