How to post two values in an option field?

前端 未结 6 2141
野性不改
野性不改 2020-12-01 22:38

I\'d like to post two values in one drop down option and I\'m not sure about the best way to approach it.

The drop down list pulls data in from an external service.

6条回答
  •  佛祖请我去吃肉
    2020-12-01 23:22

    You cannot post two values unless both of them appear in the value attribute. You can place both in, separated by a comma or hyphen and explode() them apart in PHP:

    // Place both values into the value attribute, separated by "-"
          
    

    Receiving them in PHP

    // split the contents of $_POST['data'] on a hyphen, returning at most two items
    list($data_id, $data_name) = explode("-", $_POST['data'], 2);
    
    echo "id: $data_id, name: $data_name";
    

提交回复
热议问题