Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Multiple Form Values in One Field To Submit To Scripts?

2:40 pm on Sep 11, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:May 8, 2006
votes: 0

I need to have a form field that holds two values instead of one to get the following accomplished:

Let's say I'm selling blue, red, and green widgets. I have a radio button that chooses which one you want to purchase. What I need to happen, is when the form posts to a PHP script, is to have a variable available for both the name of the product chosen, as well as the price of that product.

Kind of like: ( I know this won't work, but it illustrates my point)

<input type="radio" name="widgets" value1="Blue Widget" value2="$50">BLUE WIDGETS</input>

<input type="radio" name="widgets" value1="Green Widget" value2="$75">GREEN WIDGETS</input>

<input type="radio" name="widgets" value1="Red Widget" value2="$25">RED WIDGETS</input>

Any suggestions are greatly appreciated!

2:52 pm on Sept 11, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Apr 30, 2006
votes: 0

Since only the 'value' is sent to the script that's all you get, so you have to work with it. You have at least two options:

1) use one field
2) use two fields

Option 1 can easily be accomplished by making a value like this:
value="red widget-$50" and then using php explode() on the '-' to get your two values.

Option 2 can be accomplished by using an array
name="widget['type']" value="green"
name="widget['price']" value="50"
This way you can handle the data as one 'variable' (widget) in the script.

I recommend option one.