Welcome Guest, Not a member yet? Register   Sign In
ion_auth Groups issue
#1

[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(
                  '1' => lang('create_admin_storeadm'),
                  '4' => lang('create_admin_reports'),
                  '3' => lang('create_admin_superadm')
                );

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 #, #?
#2

[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.
#3

[eluser]Aken[/eluser]
Creating the dropdown is correct. What does $groups look like after you retrieve it?
#4

[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]'));
if (isset($this->input->post('groups[1]')))
{
array_push($group, $this->input->post('groups[1]'));
}
if (isset($this->input->post('groups[2]')))
{
array_push($group, $this->input->post('groups[2]'));
}

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]'));
            if ($this->input->post('groups[1]'))
            {
                array_push($groups, $this->input->post('groups[1]'));
            }
            if ($this->input->post('groups[2]'))
            {
            array_push($groups, $this->input->post('groups[2]'));
            }
(which I changed to since the first method is not possible as my IDE tells me it cant use a method return value)

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]
#5

[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.
#6

[eluser]The Revel[/eluser]
Ok, approaching it a bit differently, and it works

Code:
$groups = array();
            if ($this->input->post('admin') == '1')
            {
                array_push($groups, $this->input->post('admin'));
            }
            if ($this->input->post('reports') == '3')
            {
                array_push($groups, $this->input->post('reports'));
            }
            if ($this->input->post('super') == '4')
            {
                array_push($groups, $this->input->post('super'));
            }

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?
#7

[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

Message: Invalid argument supplied for foreach()

Filename: models/ion_auth_model.php

Line Number: 804
I tried this as well to no avail:
Code:
$groups = $this->input->post('groups[]');
#8

[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');
print_r($groups);
#9

[eluser]The Revel[/eluser]
Its only printing the last selected option (going back to my original method of multiselect)
#10

[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); ?>
When it should have been
Code:
<?php echo form_multiselect('groups[]', $options); ?>

Now it prints the array.




Theme © iAndrew 2016 - Forum software by © MyBB