简体   繁体   中英

Form_Dropdown() in Codeigniter

I need help on how to use the form_dropdown in Codeginiter project.

View file: my_test.php code as this,

<?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);
?>

Controllers file mytest.php code as this,

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;
}

I did read the form_dropdown portion on CI UserGuide. unfortunately I didn't find how to handle post data in send() . Thanks.

To get the dropdown's selected value, you need to get $_POST['myfilter'] (assuming "myfilter" is the name of your dropdown)

In general, to debug POST data, you might want to do a "var_dump($_POST)" That will show you all the POST data and help you figure out how to retrieve each value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM