Welcome Guest, Not a member yet? Register   Sign In
validation prep_for_form array data bug
#1

[eluser]Wilker[/eluser]
When you post some array data in post (like multiple checkbox) script generate warning because the function tries use str_replace in one array. the real bug is only in one line that is not where he was to be, this is the actually prep_for_form function:

Code:
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));
}

for fix this problem, just add a line after foreach inside is_array if, like this:

Code:
function prep_for_form($data = '')
{
    if (is_array($data))
    {
        foreach ($data as $key => $val)
        {
            $data[$key] = $this->prep_for_form($val);
        }
        
        return $data; //line added
    }
    
    if ($this->_safe_form_data == FALSE OR $data == '')
    {
        return $data;
    }

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

this makes the function returns array data prepared, and the script don't reach str_replace this way.




Theme © iAndrew 2016 - Forum software by © MyBB