CodeIgniter Forums

Full Version: Validation - Array to string conversion error (line 709)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]palaniappanc[/eluser]
I'm getting an unexpected error (array to string conversion in validation.php on line 709).
Line 709: return str_replace(array("'", '"', '<', '>'), array("'", "&quot;", '&lt;', '&gt;'), stripslashes($data));

I'm trying to validate a form. Part of it contains a variable number of text fields, and so I've used name="printfilenames[]" to get every input as an array. If I submit the form without any data at all, I get the following as my $_POST array (job_id is a hidden input that is automatically populated).

array
'job_id' => string '22' (length=2)
'printfilenames' =>
array
0 => string '' (length=0)
'filesavedto' => string '' (length=0)
'instructions' => string '' (length=0)
'jhb' => string '' (length=0)
'pjhb' => string '' (length=0)

These are my validation rules:
Code:
$rules['printfilenames']="callback_printfilenames_check|required";
$rules['filesavedto']="trim|required|xss_clean";
$rules['instructions']="trim|required|xss_clean";
$rules['jhb']="callback_jhb_check|required";
$this->validation->set_rules($rules);

The only one that is an array is printfilenames

Here is the printfilenames check function
Code:
function printfilenames_check($printfilenames)
    {
        $errors=0;
        foreach($printfilenames as $it=>$printfilename)
        {
            if(trim($printfilename)=='')
            {
                $errors++;
            }
        }
        $this->validation->set_message('filenames_check', 'All Print Filenames are required');
        global $printfilenamesJson;
        $printfilenamesJson=json_encode($printfilenames);
        if($errors>0)
        {
            return FALSE;
        }
        else
        {
            return TRUE;
        }
    }

The error comes (obviously) after calling $this->validation->run()

I checked the validation.php file, which seems to take care of looking at arrays if present. Why is this error being generated? Any ideas on what I can do?

Thanks!

El Forum

[eluser]vadivelan[/eluser]
The complete solution has been given here:
http://ellislab.com/forums/viewthread/73012/

El Forum

[eluser]palaniappanc[/eluser]
vadivelan, thankyou!