I'm setting up an eCommerce website and I need to select product quantity user enters in drop down. I have tried this but it gives me last quantity not the selected. I'm still in the process of creating the addtocart.php file but before that I need to pass the values so that I can use them in a later stage.
I have implemented the following code
<div class="product-cartq"> <div class="product-quantity pull-left"> <span>Quantity:</span> <select name="quantity_option"> <?php for($qty = 1; $qty < 11; $qty++){ echo '<option value="'.$qty.'">'.$qty.'</option>'; }?> </select> </div> <div class="btn_addtocart"> <form method="GET" action="cart.php" enctype="multipart/form-data"> <input type="hidden" name="product_id" value="<?php echo $product_id; ?>"> <input type="hidden" name="quantity_option" value="<?php echo $qty; ?>"> <input class="btn btn-primary btn-submit" type="submit" name="add_to_cart" value="add to cart"/> </form> </div> </div>
I can't proceed as I'm unable to get the value. Any suggestions or improvements on this?
Do this:
<form method="GET" action="cart.php" enctype="multipart/form-data">
<div class="product-cartq">
<div class="product-quantity pull-left">
<span>Quantity:</span>
<select name="quantity_option">
<?php for($qty = 1; $qty < 11; $qty++){
echo '<option value="'.$qty.'">'.$qty.'</option>';
}?>
</select>
</div>
<div class="btn_addtocart">
<input type="hidden" name="product_id" value="<?php echo $product_id; ?>">
<input type="hidden" name="quantity_option" value="<?php echo $qty; ?>">
<input class="btn btn-primary btn-submit" type="submit" name="add_to_cart" value="add to cart"/>
</div>
</div>
</form>
选择控件在表单标签之外。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.