开发者

CodeIgniter: Getting data from form array into post array

I'm racking my开发者_Python百科 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.


Why not just do:

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

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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜