2

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.

2 Answers 2

8

Why not just do:

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

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

Sign up to request clarification or add additional context in comments.

2 Comments

That works, though I'd still like to know why it didn't work when pulling individual items out of that array.
I don't think you can do: $this->input->post('options[is_rental]') in CI as of yet.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.