Skip to content Skip to sidebar Skip to footer

How To Retrieve Multiple Text Box Values From Single Form Using 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,withi

Solution 1:

If I understand correctly, you want to check whether a quantity was filled in for any number of products, if so, process accordingly, right?

// controller method that receives posted form data$quantity = $this->input->post('quantity');
foreach($this->input->post('product_id') as$key => $id){
    if($quantity[$key]){
        //there's a quantity for this product
    }
}

Solution 2:

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);
               }
         } 
      }

}
?>

Post a Comment for "How To Retrieve Multiple Text Box Values From Single Form Using Php/codeigniter?"