开发者

storing multiple selections from html form in PHP array (I'm using Codeigniter)

I've got an HTML form which allows a user to select multiple options in a dropdown. I then pass that data on as post data to a PHP backend (I'm using codeigniter for the backend, and the data is being passed to a model).

In javascript, I can log the value being passed, and if there are multiple values, it shows as a proper, comma separated string of values. But if log the value in PHP, it only lists the last of the multiple values. How do I get it to retain all selections? This is my code:

FORM:

<form action="http://localhost:8888/index.php/control_form/add_all" method="post" accept-charset="utf-8">
<label for="sel_dep">Member Dependencies</label> 
<select id="sel_dep" name="sel_dep" 开发者_StackOverflowmultiple> 
    <option value=""></option> 
    <option value="4">Soundgarden</option>
    <option value="5">Rage Against the Machine</option>
    <input type="submit" name="submit" value="Submit"  />       
</select> 
</form>

PHP Codeigniter Model:

function edit_member(){
  if (isset($_POST['submit'])) {
    $v_memberdep = $this->input->post('sel_dep');
    log_message('debug', 'DEP: ' . $this->input->post('sel_dep'));
  }
}


Set the name of your select box to f_memberdep[] the [] will tell PHP that it should be passed as an array so you will receive all values.

Also should point out that your logging a field called sel_dep when your select box is called f_memberdep but that's probably just a formatting thing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜