MODX parse error function implode (is it me or modx?)
        Posted  
        
            by Ian
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Ian
        
        
        
        Published on 2010-05-31T11:03:53Z
        Indexed on 
            2010/05/31
            12:53 UTC
        
        
        Read the original article
        Hit count: 307
        
Hi, I cannot for the life of me figure this out, maybe someone can help.
Using MODX a form takes user criteria to create a filter and return a list of documents. The form is one text field and a few checkboxes. If both text field and checkbox data is posted, the function works fine; if just the checkbox data is posted the function works fine; but if just the text field data is posted, modx gives me the following error:
Error: implode() [function.implode]: Invalid arguments passed.
I've tested this outside of modx with flat files and it all works fine leading me to assume a bug exists within modx. But I'm not convinced. Here's my code:
<?php
$order = array('price ASC'); //default sort order  
if(!empty($_POST['tour_finder_duration'])){ //duration submitted  
 $days = htmlentities($_POST['tour_finder_duration']); //clean up post  
 array_unshift($order,"duration DESC"); //add duration sort before default  
 $filter[] = 'duration,'.$days.',4'; //add duration to filter[] (field,criterion,mode)  
 $criteria[] = 'Number of days: <strong>'.$days.'</strong>'; //displayed on results page  
}  
if(!empty($_POST['tour_finder_dests'])){ //destination/s submitted  
 $dests = $_POST['tour_finder_dests'];  
 foreach($dests as $value){ //iterate through dests array  
  $filter[] = 'searchDests,'.htmlentities($value).',7'; //add dests to filter[]  
  $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>';  
 }  
 $dests_array = implode(', ',$dests_array);  
 $criteria[] = 'Destinations: '.$dests_array; //displayed on results page  
}  
if(is_array($filter)){  
 $filter = implode('|',$filter);//pipe-separated string  
}  
if(is_array($order)){  
 $order = implode(',',$order);//comma-separated string  
}  
if(is_array($criteria)){  
 $criteria = implode('<br />',$criteria);  
}  
echo '<br />Order: '.$order.'<br /> Filter: '.$filter.'<br /> Criteria: '.$criteria;
//next: extract docs using $filter and $order, display user's criteria using $criteria...  
?>
The echo statement is displayed above the MODX error message and the $filter array is correctly imploded.
Any help will save my computer from flying out the window.
Thanks
© Stack Overflow or respective owner