0
votes

Update 4-June-2010: This appears to be a bug in MODx v 1.0.3, nothing to do with the implode function but rather a problem with mis-matched datatypes in the resulting filter clause. Bug has been filed with JIRA: MODX-2035.

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

2
"modx" as in modxcms.de ? - VolkerK
And does the error message contain a location like 'foo.php:23'? Which of the four implode()s in the code snippet causes the error? - VolkerK
File: /includes/document.parser.class.inc.php(770) : eval()'d code Line: 13 The error does not state which implode() is causing the problem but it seems to be on the $filter array. All other implode() functions work if I comment this one out. - Ian
In document.parser.class.inc.php on line 770 eval() is invoked. And the error occurs on line 13 of the code passed to eval(). - VolkerK
Yes. An oddity is when I change the code passed to eval() - moving lines up and down with filler statements like "echo" and putting braces{} on new lines - the error remains line 13. Have not once been able to get a different line. Plus there is no implode() on or near line 13. I will post this problem at the MODX forum and see what they say. Thanks for your help so far. - Ian

2 Answers

0
votes

I think your problem lies here :

$dests_array = implode(', ',$dests_array); 

$dest_array may be empty and not even initialized if $dests is empty.

0
votes

This really should be posted in the MODx forums. I love stackoverflow, but MODx is more niche.