![]() |
ion_auth Groups issue - 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: ion_auth Groups issue (/showthread.php?tid=51968) |
ion_auth Groups issue - El Forum - 05-24-2012 [eluser]The Revel[/eluser] Ok, I am trying to assign Multiple groups using the form_multiselect() function. Here is the code the pertains to the issue: Setting the options in the controller Code: $this->data['options'] = array( Echoing the form in the view: Code: <?php echo form_multiselect('groups', $options); ?> Processing the groups in the controller: Code: $groups = array($this->input->post('groups[]')); If I select the options for group IDs 3 and 4, the database inputs groups 0 and 2... I have a feeling its the second part in the controller... the art where I set groups tot he array. How do I get the selections from groups[] to be #, #? ion_auth Groups issue - El Forum - 05-24-2012 [eluser]The Revel[/eluser] Just a thought as I leave the office to head home after a long day of figuring things out. I have a feeling its putting in the Array's ID and not the values... I.E. If I select the options for 1 and 3 (Store admin and Super admin) Its putting in 0 and 2 (since arrays start at 0 instead of 1) instead of its assigned values 1 and 3. If I were to select 3 only, it would put in 2 (which is Member and not super admin) So how do I make it so that it outputs the associated values of the array instead of the array's IDs? Hope that makes sense. ion_auth Groups issue - El Forum - 05-24-2012 [eluser]Aken[/eluser] Creating the dropdown is correct. What does $groups look like after you retrieve it? ion_auth Groups issue - El Forum - 05-25-2012 [eluser]The Revel[/eluser] [quote author="Aken" date="1337925027"]Creating the drop down is correct. What does $groups look like after you retrieve it?[/quote] Its an array, when I echo groups it simply says array, so its getting information assigned to it, just not the right info. I have a feeling I have to some how extract the groups[] array somehow but unfortunately I am not sure which way to go on that. I am assuming something along the lines of groups[$i] method. Something along the lines of Code: $group = array($this->input->post('groups[0]')); I have not tested this of course, will try it now and see if I am right. [EDIT] Well, that didn't work, neither did Code: $groups = array($this->input->post('groups[0]')); Anyone have any idea how to make this work? I want the super admins to be able to create users with Multiple groups. Alternately I could use check boxes I guess, but fear I would run into the same problem. [/EDIT] ion_auth Groups issue - El Forum - 05-25-2012 [eluser]Matalina[/eluser] Code: $groups = $this->input->post('groups'); will give you an array from your posts no need to do what you are doing. print_r groups and see if it's actually returning what you expect. ion_auth Groups issue - El Forum - 05-25-2012 [eluser]The Revel[/eluser] Ok, approaching it a bit differently, and it works Code: $groups = array(); However this posses a problem... I want the form to validate this, but because I am using separate variables, I cannot. Can someone point me in the right direction? How can I use check boxes all with the same name and have the same effect? ion_auth Groups issue - El Forum - 05-25-2012 [eluser]The Revel[/eluser] [quote author="Matalina" date="1337960425"] Code: $groups = $this->input->post('groups'); will give you an array from your posts no need to do what you are doing. print_r groups and see if it's actually returning what you expect. [/quote] In doing so I get Code: Severity: Warning Code: $groups = $this->input->post('groups[]'); ion_auth Groups issue - El Forum - 05-25-2012 [eluser]Matalina[/eluser] We need to see your array from post either: Code: print_r($this->input->post()); or Code: $groups = $this->input->post('groups'); ion_auth Groups issue - El Forum - 05-25-2012 [eluser]The Revel[/eluser] Its only printing the last selected option (going back to my original method of multiselect) ion_auth Groups issue - El Forum - 05-25-2012 [eluser]The Revel[/eluser] Found the issue... Above AKen told me my coding was right, but it was wrong... I had Code: <?php echo form_multiselect('groups', $options); ?> Code: <?php echo form_multiselect('groups[]', $options); ?> Now it prints the array. |