2011-04-02 52 views
0

我需要關於如何在Codeginiter項目中使用form_dropdown的幫助。Codeigniter中的Form_Dropdown()

查看文件:my_test.php代碼,因爲這,

<?php 
    // basic filter form 
    $attributes = array('class' => 'formstyle', 'id' => 'myfilterform'); 
    echo form_open('mytest/send', $attributes); 
    $options = array(
        'all' => 'Pls Select Filter', 
        'male' => 'Male List', 
        'female' => 'Female List', 
       ); 
    echo form_dropdown('myfilter', $options, 'male'); 
    echo form_submit('myfiltersubmit', ' GO '); 
    $string = "</div></div>"; 
    echo form_close($string); 
?> 

控制器文件mytest.php代碼,因爲這,

function index() 
{ 
    $data['title'] = "Hello"; 
    $this->load->view('my_test', $data); 
} 

function send() 
{ 
     $mypostdata = $_POST['options']; // I can't get the post data here. 
     echo $mypostdata; 
} 

我看過的CI UserGuide的form_dropdown部分。不幸的是我沒有找到如何處理send()中的發佈數據。謝謝。

回答

3

要獲得下拉列表的選擇的價值,你需要得到$ _ POST [「myfilter」](假設「myfilter」的是你的下拉菜單的名稱)

一般來說,調試POST數據,你可能要做一個「var_dump($ _ POST)」這將顯示所有的POST數據,並幫助你找出如何檢索每個值。

+0

'$ _POST ['myfilter']'工作得很好。謝謝。 – 2011-04-02 05:26:59

+0

'var_dump($ _ POST)'也可以。我從來沒有嘗試過。驚人...!!! – 2011-04-02 05:28:52

+3

此外,您可能希望使用Codeigniter內置的Input類,如$ filter = $ this-> input-> post(「myfilter」),它會爲您執行很多安全檢查。 – Dormouse 2011-04-02 07:38:37

相關問題