문제

I have tried this a few different ways including as a hidden value. I have 2 separate values I need assigned to $_SESSION variables, id and cust_name. Assigning them to the session in the foreach loop does not work because it breaks the echo output. The only way I found to get both values to the next url was by concatenating them to a delimiter but that appears to be causing me issues. Is there another/better way to assign .$item['id'].":".$item['cust_name']. to individual session variable 'or' separate element in a $_POST value= ? http://i.imgur.com/6AfDMWs.png

 <?php
     foreach ($result as $item){
                echo '<option value='.$item['id'].":".$item['cust_name'].'>';
                //echo '<option type="hidden" value='.$item['cust_name'].'>';
                echo ($item['cust_name'] .",". $item['cust_addr'] .",". $item['cust_phone'].","
. $item['id']."<br />\n");
                echo '</option>';
        }
도움이 되었습니까?

해결책 2

The only way you can push 2 variables to a second URL is by using javascript to populate a hidden variable on post, pulling information from a "data" attribute.

For example, you'd define the following as your option...

<option data-customerid="123" name="customername" value="Marty McFly">Marty McFly, 123 Fake Street, 555-555-5555</option>

Then, using javascript...

$("#myform").submit( function(eventObj){
  $(this).append('<input type="hidden" name="customerid" value="'+$('#myselect').find(':selected').attr('data-customerid');+'" /> ');               
  return true;
  });

return true at the end, then allows for the form to be posted in your normal way.

You will need to change #myform and #myselect in the above to the ID of your form, and the ID of your select element respectively. If you want to send any more additional fields, repeat the line starting with `$(this), changing the ID accordingly.

다른 팁

Try closing your value tag like this, otherwise if cust_name contains space, it will be missed

echo '<option value="'.$item['id'].":".$item['cust_name'].'">';
              //    ^                                      ^ Add double quotes here
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top