two values for one name in input

前端 未结 5 2136
天涯浪人
天涯浪人 2021-01-05 05:39

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



        
相关标签:
5条回答
  • 2021-01-05 06:15

    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:

        <input type="radio" name="name" value="value1-value2"/> 
    
    0 讨论(0)
  • 2021-01-05 06:23

    Why not do:

    <input type="radio" name="name" value="value1#value2" />
    

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

    0 讨论(0)
  • 2021-01-05 06:26

    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.

    0 讨论(0)
  • 2021-01-05 06:27

    Use this :

    <input type="radio" name="name[]" value1="value1" />
    <input type="radio" name="name[]" value1="value2" />
    

    returns array

    0 讨论(0)
  • 2021-01-05 06:30

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

    <input type="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"

    0 讨论(0)
提交回复
热议问题