CodeIgniter: Getting data from form array into post array

Question!

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.



Answers

I've noticed the same thing with CodeIgniter. If you pass the index to the form validation rule, it works fine, but to get the data into another var, you need to first put the post array into a temp variable and then access that index. You cannot access indexes on POST array's by using $this->input->post

By : Shivaas


This video can help you solving your question :)
By: admin