Skip to content Skip to sidebar Skip to footer

Two Values For One Name In Input

I have one input (type radio) that I want to insert it 2 values, something like that: And after draw each

Solution 1:

Well, not the way I would do it, but you could use a delimiter for your value(s)

<inputtype="radio" value="Value1|Value2" name="two_values" />

Then, in PHP, just list($value1,$value2) = explode('|', $_POST['two_values']);

EDIT As @user387302 said, you would obviously be limited to not having any values containing your delimiter, for example value="One|PipedVariable|andAnother" would not work to extract two values of "One|PipedValue" and "andAnother"

Solution 2:

Why not do:

<inputtype="radio" name="name" value="value1#value2" />

and then split on "#" (or any other symbol) server-side?

Solution 3:

If I understand your question correctly, can you set the value of your radio to something like "value1-value2" and then in your php just seperate value1 from value2 with explode(). You could use any other seperator other than '-' too.

Edit

based on your exmaple:

    <inputtype="radio" name="name" value="value1-value2"/> 

Solution 4:

Can't do it.

You need either a hidden input (which you say you don't want) or use value="value1,value2" and then explode in the PHP script.

Solution 5:

Use this :

<inputtype="radio" name="name[]" value1="value1" />
<inputtype="radio" name="name[]" value1="value2" />

returns array

Post a Comment for "Two Values For One Name In Input"