homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Gold Sponsor 2015!
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Multiple Form Values in One Field To Submit To Scripts?

5+ Year Member

Msg#: 3078852 posted 2:40 pm on Sep 11, 2006 (gmt 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!



5+ Year Member

Msg#: 3078852 posted 2:52 pm on Sep 11, 2006 (gmt 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.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved