September 23, 201313 yr Hello all, I'm currently making an online order form for a client. It includes products which prices change based on selections made via dropdown. Different styles of product = different prices per style. This has become an issue, as I need the dropdown value to equal the price of the product (for calculating the entire order price), but I need to also have the text value of the dropdown which needs to be sent via PHP contact form. The HTML: <form method="post" action="..."> <select name="product"> <option value="1.00">Product Style A</option> <option value="2.00">Product Style B</option> <option value="3.00">Product Style C</option> </select> <input type="submit" value="submit" /> </form> The PHP: $product = $_POST['product']; The way it is now: "Product Style A" is selected, so $product = 1.00 The way it needs to be: "Product Style A" is selected, so $product = Product Style A Is there a way that I can get the title of the dropdown with PHP, instead of the value?
September 23, 201313 yr you can use a PHP array and store the values and title in there like so <?php $values = array('1.00'=>'Product Style A', '2.00'=>'Product Style B', '3.00'=>'Product Style C'); $productValue = $_POST['product']; $productDescr = $values[$_POST['product']]; ?>
September 23, 201313 yr Author Awesome, thank you so much. Is there a way to do this if, for example, Product Style A and Product Style B are both the same values?
September 23, 201313 yr the only way i can think of is having the value as 1.0000001 for product A and then 1.0000002 for product B then they would be different values but when processing the data you can just round to two decimal points giving you 1.00 Edited September 23, 201313 yr by D4Y0
Create an account or sign in to comment