Hi, I have a most perplexing problem requiring my very first forum topic ever. I’m taking user input to make a filter for the ditto call that displays a list of products (holiday tours in this case filtered by number of days and preferred destination/s).
If user selects one or more destinations AND a duration, the results are displayed; if user selects one or more destinations ONLY, the results are displayed. However, if user selects duration ONLY, the following error is returned:
Order: duration DESC,price ASC
Filter: duration,100,4
Criteria: Number of days: 100
« MODx Parse Error »
MODx encountered the following error while attempting to parse the requested resource:
« PHP Parse Error »
PHP error debug
Error: implode() [function.implode]: Invalid arguments passed
Error type/ Nr.: Warning - 2
File: /manager/includes/document.parser.class.inc.php(770) : eval()’d code
Line: 13
Parser timing
MySQL: 0.4773 s (1195 Requests)
PHP: 0.4081 s
Total: 0.8854 s
Note the echoed text above the error message is correctly imploded and the post input displayed:
Order: duration DESC,price ASC
Filter: duration,100,4
Criteria: Number of days: 100
I’m stuck. If anybody can help it will save me from ruin. My code is posted below up to the point where the results are filtered and displayed. The error line is 13 but I cannot get that to change at all (by adding/removing lines) and by trial and error the implode() function in question seems to be the $filter array:
$order = array('price ASC'); //default sort order
if(!empty($_POST['tour_finder_duration'])){ //text field posted
array_unshift($order,'duration DESC'); //add sort order to beginning of array
$days = htmlentities($_POST['tour_finder_duration']); //clean up post
$filter[] = 'duration,'.$days.',4'; //add criterion to filter array
$criteria[] = 'Number of days: <strong>'.$days.'</strong>';//display user's input
}
if(is_array($_POST['tour_finder_dests'])){ //checkbox array posted
$dests = $_POST['tour_finder_dests']; //clean up and add criteria to filter array
foreach($dests as $value){
$filter[] = 'searchDests,'.htmlentities($value).',7';
$params['docid'] = $value;
$params['field'] = 'pagetitle';
$pagetitle = $modx->runSnippet('GetField',$params);
$dests_array[] = '<a href="[~'.$value.'~]" title="Read more about '.$pagetitle.'" class="tourdestlink">'.$pagetitle.'</a>';
}
if(is_array($dests_array)){
$dests_array = implode(', ',$dests_array);
}
$criteria[] = 'Destinations: '.$dests_array;
}
if(is_array($filter)){
$filter = implode('|',$filter);
}
if(is_array($order)){
$order = implode(',',$order);
}
if(is_array($criteria)){
$criteria = implode('<br />',$criteria);
}
//test output works:
echo '<br />Order: '.$order.'<br /> Filter: '.$filter.'<br /> Criteria: '.$criteria;
if(!empty($filter)){
//... display results
}
Apologies for the long post and any forum no-nos. My setup is as follows:
[tt]MODx: 1.0.3
Server: PHP: 5 | Apache 2 | Mac OS X
Database: MySQL: 5 | Large tables: _manager_log (1.22MB); _event_log (2.72MB)
Client: Firefox 3 | Mac OS X[/tt]