Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

(PHP): Getting Dropdown Title instead of Value

Featured Replies

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?

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']];

?>
  • 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?

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 by D4Y0

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.