PHP post中的html multi <select>数组</select>

时间:2010-08-20 16:59:34

标签: html arrays select post

<form>        
    <input class="date-pick"  type="text" value="2010/08/02" name="date" />
    <table id="events_selection">            
        <tr>                
            <td>                    
                <img src="/admin/ajax/image.php?filename=/media/immagini/danieledaniela/1.jpg&maxw=200" />
                <select name="1">
                    <option value="0"> NESSUN EVENTO </option>                        
                    <option value="5">anelli</option>                        
                    <option value="8">ballo</option>                        
                    <option value="6">cerimonia in chiesa</option>                        
                    <option value="13">dettagli</option>                        
                    <option value="9" selected="selected"><strong>festa</strong></option>                        
                    <option value="4">gli sposi</option>                        
                    <option value="1">la sposa</option>                        
                    <option value="3">lancio del riso</option>                        
                    <option value="2">lo sposo</option>                        
                    <option value="11">preparazione sposa</option>                        
                    <option value="10">preparazione sposo</option>                        
                    <option value="7">ristorante</option>                        
                    <option value="12">varie</option>                        
                </select>
            </td>
            <td>
                <img src="/admin/ajax/image.php?filename=/media/immagini/danieledaniela/30.jpg&maxw=200" />
                <select name="31">
                    <option value="0"> NESSUN EVENTO </option>                        
                    <option value="5">anelli</option>                        
                    <option value="8">ballo</option>                        
                    <option value="6">cerimonia in chiesa</option>                        
                    <option value="13">dettagli</option>                        
                    <option value="9">festa</option>                        
                    <option value="4">gli sposi</option>
                    <option value="1">la sposa</option>                        
                    <option value="3">lancio del riso</option>                        
                    <option value="2">lo sposo</option>                        
                    <option value="11">preparazione sposa</option>                        
                    <option value="10">preparazione sposo</option>                        
                    <option value="7">ristorante</option>                        
                    <option value="12">varie</option>                        
                </select>
            </td>                
        </tr>
    </table>
</form>​​​​​​​​

HI,在这样的情况下(这是一个例子,有很多选择和其他输入)发布此表单会给出一个像这样的$ _POST

array {
  date => "2010/08/09"
  input1 => "bla"
  input3 => "bla2"
  //list of selection
  1 => 2
  2 => 4
  3 => 5
  //ends list of selection
  input 4 => "bla4"
}

我可以直接从HTML表单中将<select>放在单独的数组中,因为它们代表一个分组数组吗?

array {
  date => "2010/08/09"
  input1 => "bla"
  input3 => "bla2"
  //list of selection
  array {
      1 => 2
      2 => 4
      3 => 5
  }
  //ends list of selection
  input 4 => "bla4"
}

谢谢!

1 个答案:

答案 0 :(得分:4)

此:

<select name="selection[1]">
    <option>1</option>
    <option>2</option>
    <option>3</option>
</select>
<select name="selection[2]">
    <option>1</option>
    <option>2</option>
    <option>3</option>
</select>

会回来:

'selection' => array(1 => 1, 2 => 1)

猜猜你正在寻找什么? : - )