Multi-dimensional fields in set_radio/set_checkbox
The form_helper should relay on CI's input->post() method instead of using $_POST array for setting things just like set_value is doing right now.
Currently trying to set things like options['label']['something'] will fail as it cannot be translated using the $_POST directly.
Could you give an example of what fails?
Re-Producing the issue isn't easy, it happens when $OBJ === FALSE (when you don't have validation loaded) OR when you have validation loaded & you're not validating the field in question.
You may test it however you want by supplying checkboxes or radios
e.g: for checkbox name => 'options[type][check][]' e.g: for radio name => 'options[type][other]'
This can be fixed by using $CI->input->post in the form_helper, but I have no idea on how to get it fixed for the form_validation as you're only loading data for the fields that are being validated.
It's not even necessarily POST data if you're using the library, so don't worry about that.
I guess a fix for this would also requires changing '_field_data' from protected to public in the form_validation so you can check if there are field data, a rule is set so form_validation would take care of it, otherwise the form_helper will take care of it.
something like
if ($OBJ === FALSE OR ! isset($OBJ->_field_data[$field]) )
// let the form_helper handler it
No, the library stays as it is. If you'll be using it - you should have rules for all fields.
That wasn't nice, Anyway after Looking again at the helper, looks like $OBJ->has_rule($field) can be used so no modification would be needed to the validation library.
The current way shown there isn't following the standards applied in other setters, Look at set_value for example, it works with or without form_validation.
Currently if you auto load form_validation, You'll be rendering half (if not most) of the setters functions useless when not using validation for the given field which makes no sense at all (having validation class loaded doesn't mean the setter should go there unless there are rules defined for the given field).
Yes, has_rule() is applicable. In fact, it was introduced for that same purpose - look at set_value(). :)
How about now?
Close, but for checkbox the last return should be changed to make it work.
return ( ( is_array($input) && in_array($value, $input, TRUE) ) OR ( $input === $value) ) ? ' checked="checked"' : '';
Just noticed, there's a typo in set_select where it says "checked=selected" instead of "selected=selected"
And this one too requires the same changes I mentioned in my previous comment, as you may supply multiple=multiple when you make a dropdown menu.
Anything else?
Looks perfect now, Thank you.
You're welcome. :)