CodeIgniter: Getting data from form array into post array

17,464

Why not just do:

$data = $this->input->post('options');

Then $data['is_rental'] should == 1

Share:
17,464
mdvaldosta
Author by

mdvaldosta

I'm a hobby programmer in C#, PHP, SQL, XHTML and CSS. Learning more everyday, although it pales in comparison to many of the programmers here.

Updated on June 05, 2022

Comments

  • mdvaldosta
    mdvaldosta almost 2 years

    I'm racking my brain. I'm using CodeIgniter, trying to get a value from a form checkbox into a data array to send off to the database. Here are the snippets:

    Form (view):

    <label>Rental Car?</label><input type="checkbox" name="options[is_rental]" value="1" <?php echo set_checkbox('options[is_rental]', '1', FALSE); ?> />
    

    Controller:

    $data['is_rental'] = $this->input->post('options[is_rental]');
    

    Now, during this process I'm also validating and re-populating the form with data using options[is_rental] and that works just fine. Using var_dump I get:

    Dumps (with the checkbox checked) from the controller:

    var_dump($this->input->post('options[is_rental]'))
    

    Returns

    bool(false)
    

    and...

    var_dump($this->input->post('options'))
    

    Returns

    array(3) { ["engine"]=> string(4) "4cyl" ["transmission"]=> string(9) "automatic" ["is_rental"]=> string(1) "1" }
    

    For what it's worth, I can't get to those other values in the array either.