Welcome Guest, Not a member yet? Register   Sign In
Strange callback validation error for an array
#1

[eluser]Isos[/eluser]
In a user profile, user is asked to check at least 5 checkboxes out of 30.
The checkboxes are named as discplines[] as following:
Code:
<input type="checkbox" name="disciplines[]" value="<?$discipline->id;?>" />
It means $_POST['disciplines'] is an array of disciplines IDs
So I created a callback functions as following:
Code:
function _check_if_more_than_five($str){
    if (count($str) > 5){
         $this->validation->set_message("_check_if_more_than_five","You cannot check more than five disciplines");

            return false;
        } else {
            return true;
        }

    }

The good thing about this is that it works, but the bugging ugly thing is that I get this error at the top of the page:

A PHP Error was encountered

Severity: Notice

Message: Array to string conversion

Filename: libraries/Validation.php

Line Number: 709



Where Line Number: 709 in libraries/Validation.php is as following:
Code:
return str_replace(array("'", '"', '<', '>'), array("'", "&quot;", '&lt;', '&gt;'), stripslashes($data));
The whole function is as following:
Code:
/**
     * Prep data for form
     *
     * This function allows HTML to be safely shown in a form.
     * Special characters are converted.
     *
     * @access    public
     * @param    string
     * @return    string
     */
    function prep_for_form($data = '')
    {
        if (is_array($data))
        {
            foreach ($data as $key => $val)
            {
                $data[$key] = $this->prep_for_form($val);
            }
        }
        
        if ($this->_safe_form_data == FALSE OR $data == '')
        {
            return $data;
        }

        return str_replace(array("'", '"', '<', '>'), array("'", "&quot;", '&lt;', '&gt;'), stripslashes($data));
    }

I am trying to figure out what's wrong and how I may solve this. But, when it comes to manipulating a ci script to solve a problem I tend to consult in here.

Any help will be appreciated.

Thanks.
#2

[eluser]Isos[/eluser]
Oh! Thanks to search Smile I found the solution here: http://ellislab.com/forums/viewthread/72192/ so don't bother .. thanks.




Theme © iAndrew 2016 - Forum software by © MyBB