CodeIgniter Forums
set_value() for getting array in return - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: set_value() for getting array in return (/showthread.php?tid=53260)



set_value() for getting array in return - El Forum - 07-17-2012

[eluser]Unknown[/eluser]
Hello Everybody,

I have download the new version of codeigniter and it give me following error when I use set_value() for getting array in return.

ERROR
------
Warning (in_array() expects parameter 2 to be array, string given in file: views/add_role_view.php on line: 123)

Actually my task is to set the checked values of checkboxes after postback.

Have a look my code.
Code:
<?php
$page_id = array();
$page_id = set_value('assignRole[]');

foreach($data as $row){
?>
<input type="checkbox"  value="<?php echo($row->page_id); ?>" name="assignRole[]" <?php if(!empty($page_id) && in_array($row->page_id, $page_id)){?>checked="checked" <?php }?> />
<?php
}
?>

$row->page_id is a unique ID coming from loop send by controller in $data variable.

It was working fine in previous version i.e. 1.7.3 but when I installed the new version it going to mass.

By the way I am using version 2.1.2

Any idea??


set_value() for getting array in return - El Forum - 07-17-2012

[eluser]Aken[/eluser]
set_value() needs the field name as interpreted by the server. I.E. if it's an array, leave out the array notation.

Code:
$page_id = set_value('assignRole');



set_value() for getting array in return - El Forum - 07-18-2012

[eluser]Unknown[/eluser]
Thanks for your reply Aken,

I tried it with
Code:
$page_id = set_value('assignRole');
But still its not working.

Now what I did
I used the following code and its working fine.

Code:
<input type="checkbox"  value="<?php echo($row->page_id); ?>" name="assignRole[]"  <?php echo(set_checkbox('assignRole', $row->page_id));?> />

Basically I saw it later that there is a function for checkbox i.e.

Code:
set_checkbox('assignRole', $row->page_id)
which returns checked="checked" if it is checked before the form submitted.

But thanks for your prompt reply.