Welcome Guest, Not a member yet? Register   Sign In
If set_checkbox() or set_radio() with arrays doesn't work...
#1

[eluser]simshaun[/eluser]
Once again, I spent literally hours racking my brain over this and trying different combinations between the view and controller...

If you have checkboxes or radios who's name is an array (ex: name="privelages[]"),
and you try to use set_checkbox('privelages[]', 'expected-value') on them, it won't work!

I was doing this because in the documentation, it says to. (But wait! It only shows using the brackets in the set_value() function.)

The solution, I'm glad to say, is to take the [] part off of the name in set_checkbox().
Code:
set_checkbox('privelages[]', 'expected-value')
...becomes...
set_checkbox('privelages', 'expected-value')

This is because the set_checkbox function was checking for a key called "privelages[]" in its version of the post array. It won't find it because PHP has converted privelages to an array already, so the post array looks something like this:
Code:
'privelages' =>
    0 => 'add'
    ,1 => 'edit'
    ,2 => 'delete'

NOT...
Code:
'privelages[]' =>
    0 => 'add'
    ,1 => 'edit'
    ,2 => 'delete'

Hope this helps someone.
#2

[eluser]no_Ob[/eluser]
Thank you simshaun

It helped me lot.
I was wondering why I can't see the posted variables in my controller




Theme © iAndrew 2016 - Forum software by © MyBB