Welcome Guest, Not a member yet? Register   Sign In
trim($this->input->post('whatever');
#1

[eluser]SaminOz[/eluser]
I just came across an issue in PHP that had me flumuxed for a while.

I had some code in this format

Code:
$data['job'] = array(
'job_ID' => NULL,
'staff_ID' => trim($this->input->post('staff_ID'))
);

which I was trying to input. I kept on getting errors as I iterated through the $job array.

The post('staff_ID') and it's siblings (which I've removed here) were all arrays sent from the page where there were multiple form elements i.e. staff_ID[].

It transpires that PHP will return the string 'Array' instead of the elements if you use trim as you might in a single key/value pair. I thought this might be useful to someone else sometime.

See also:

Quote:thek at o2 dot pl
17-Feb-2010 10:36
There is a trap when making "form prefilters". Something like
$_POST = array_map('trim', $_POST)
may be not what we wanted, because when there are arrays in form made by field[] this "prefilter" return not an array but, according to his behavior, string. So as a effect we see in var_dump not array but field = "Array" what can mess up our validation.
http://au2.php.net/manual/en/function.trim.php




Theme © iAndrew 2016 - Forum software by © MyBB