• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Spain CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: Posting Arrays
PostPosted: Wed Sep 21, 2011 4:43 pm 
Offline
Forum Members
Forum Members
User avatar

Joined: Mon Sep 28, 2009 5:25 pm
Posts: 54
I have a form that contains two lists of check boxes for filtering. Now what I'd like to be able to do is pass all the selected values as a single array so the name for the first list would filterby[category][] and the second would be filterby[neighborhood][]. Now my problem is I can't access the values of the second level array from $params (ignore for the moment that there is no module id on those names, that isn't the issue and have been remove for legibility).

If I call the value of $params['filterby'] I get an array containing two indexes. Great that's what I'm expecting, but if I try $params['filterby']['category'] or $params['filterby']['neighborhood'] all I get returned is 'Array'. The cms seems to be to-stringing the value in the second level array.

Does anyone know a way around this or am I going to have to stick with using $_POST and sanitizing the data myself?


Top
 Profile  
 
 Post subject: Re: Posting Arrays
PostPosted: Wed Sep 21, 2011 6:40 pm 
Offline
Power Poster
Power Poster

Joined: Fri Jun 06, 2008 5:54 pm
Posts: 345
You may want to do something like print_r($params['filterby']) and see exactly what is coming back. This will show you exactly how the variable is structured and you can write your code accordingly.

-S


Top
 Profile  
 
 Post subject: Re: Posting Arrays
PostPosted: Wed Sep 21, 2011 8:18 pm 
Offline
Forum Members
Forum Members
User avatar

Joined: Mon Sep 28, 2009 5:25 pm
Posts: 54
It comes back exactly as I described it

Code:
Array
(
    [category] => Array
    [neighborhood] => Array
)


Top
 Profile  
 
 Post subject: Re: Posting Arrays
PostPosted: Wed Sep 21, 2011 9:00 pm 
Offline
Power Poster
Power Poster

Joined: Fri Jun 06, 2008 5:54 pm
Posts: 345
Curious. print_r is support to be recursive. Try
Code:
print_r($params['filterby'].category);
or
print_r($params['filterby']['category']);


-S


Top
 Profile  
 
 Post subject: Re: Posting Arrays
PostPosted: Wed Sep 21, 2011 9:14 pm 
Offline
Forum Members
Forum Members
User avatar

Joined: Mon Sep 28, 2009 5:25 pm
Posts: 54
print_r($params['filterby'].category); returns
Code:
Notice: Use of undefined constant category - assumed 'category' in...
Arraycategory

print_r($params['filterby']['category']); returns
Code:
Array


Top
 Profile  
 
 Post subject: Re: Posting Arrays
PostPosted: Thu Sep 22, 2011 7:10 am 
Offline
Forum Members
Forum Members
User avatar

Joined: Sun Jul 27, 2008 1:36 am
Posts: 190
Location: USA
Hmmm. What is returned when you execute this statement...
Code:
echo is_array($params['filterby']['category']) ? 'Array' : 'not an Array';

_________________
Towering genius disdains a beaten path. It seeks regions hitherto unexplored.
--Abraham Lincoln, speech, Jan. 27, 1838


Top
 Profile  
 
 Post subject: Re: Posting Arrays
PostPosted: Thu Sep 22, 2011 4:51 pm 
Offline
Forum Members
Forum Members
User avatar

Joined: Mon Sep 28, 2009 5:25 pm
Posts: 54
it returns
Code:
not an Array

aswell as
Code:
Notice: Array to string conversion in /var/www/.../httpdocs/lib/misc.functions.php on line 417
which I suppose I should've mentioned before because this message isn't new (I hinted to it in the op though) but it might spark something for you guys


Last edited by kidcardboard on Fri Sep 23, 2011 4:52 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Posting Arrays
PostPosted: Fri Sep 23, 2011 8:46 am 
Offline
Forum Members
Forum Members
User avatar

Joined: Sun Jul 27, 2008 1:36 am
Posts: 190
Location: USA
kidcardboard wrote:
it returns
Code:
not an Array

aswell as
Code:
Notice: Array to string conversion in /var/www/vhosts/meetingscalgary.com/subdomains/dev/httpdocs/lib/misc.functions.php on line 417
which I suppose I should've mentioned before because this message isn't new (I hinted to it in the op though) but it might spark something for you guys
Hmm. That's what I suspected--not an Array.

Without knowing the version of CMSMS that you're using, it's hard to tell what code is at line 417 in the lib/misc.functions.php installed on your site.

_________________
Towering genius disdains a beaten path. It seeks regions hitherto unexplored.
--Abraham Lincoln, speech, Jan. 27, 1838


Top
 Profile  
 
 Post subject: Re: Posting Arrays
PostPosted: Fri Sep 23, 2011 4:51 pm 
Offline
Forum Members
Forum Members
User avatar

Joined: Mon Sep 28, 2009 5:25 pm
Posts: 54
I suppose I could've included that too eh...lol. I'm running 1.9.4.2 "Faanui"


Top
 Profile  
 
 Post subject: Re: Posting Arrays
PostPosted: Tue Sep 27, 2011 12:53 pm 
Offline
Forum Members
Forum Members

Joined: Tue Feb 12, 2008 10:00 am
Posts: 74
I've just come across the same issue so I did some checking.

On the front end, parameters are passed to the cleanParamHash method in misc.functions.php for cleaning. Unfortunately, this method does't recurse down the arrays so they are interpreted as strings, hence the "Array to string..." notice.

It doesn't look to me like there's a way round this, short of adding it as a feature request. I think the best option in this case is to just register the params separately or like you said, use $_POST and sanitize yourself.


Top
 Profile  
 
 Post subject: Re: Posting Arrays
PostPosted: Tue Sep 27, 2011 8:23 pm 
Offline
Forum Members
Forum Members
User avatar

Joined: Sun Jul 27, 2008 1:36 am
Posts: 190
Location: USA
tomgsd wrote:
...
It doesn't look to me like there's a way round this, short of adding it as a feature request. I think the best option in this case is to just register the params separately or like you said, use $_POST and sanitize yourself.

@kidcardboard
I'm not sure if it would help much, but you might explore registering your "array of arrays" param as CLEAN_NONE. You'd still need to clean the array elements yourself, as with $_POST, but that would keep param handling as consistent as possible... until your feature request gets implemented. Just a thought.

_________________
Towering genius disdains a beaten path. It seeks regions hitherto unexplored.
--Abraham Lincoln, speech, Jan. 27, 1838


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
A2 Hosting