We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12578
    • 12 Posts
    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]
      • 11055 ☆ A M B ☆
      • 3,112 Posts
      what does it say if you die($filter); right before implode it ?
        Rico
        Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
        MODx is great, but knowing how to use it well makes it perfect!

        www.virtudraft.com

        Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

        Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

        Maintainter/contributor of Babel

        Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
        • 12578
        • 12 Posts
        Quote from: goldsky at Jun 01, 2010, 04:15 AM

        what does it say if you die($filter); right before implode it ?

        It says: Array

        I get the same result for all posted options i.e. posting text field only, posting checkbox array only and posting both.
          • 11055 ☆ A M B ☆
          • 3,112 Posts
          what does it say if you die(print_r($filter)); ?
          use die(...) much to investigate the real result before further process.
            Rico
            Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
            MODx is great, but knowing how to use it well makes it perfect!

            www.virtudraft.com

            Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

            Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

            Maintainter/contributor of Babel

            Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
            • 12578
            • 12 Posts
            Quote from: goldsky at Jun 01, 2010, 05:26 AM

            what does it say if you die(print_r($filter)); ?
            use die(...) much to investigate the real result before further process.

            Ok, so I tried [tt]die()[/tt] after every array and each time the output was the actual array until I got to the ditto snippet call, then I got the error (see comments on each line):

            if(!empty($filter)){ //display results
            //die(print_r($filter)); //PRINTS OUT CONTENTS OF $filter ARRAY
            
             $resultsArray = array('parents'=>'3', 'tpl'=>'TourListingRowTPL', 'filter'=>$filter,'paginate'=>'1','display'=>'all','orderBy'=>$order,'noResults'=>'#####');
            //die(print_r($resultsArray)); //PRINTS OUT CONTENTS OF $resultsArray ARRAY
            
             $result = $modx->runSnippet('Ditto', $resultsArray);
            //die($result); //ERROR OCCURS BEFORE die() EXECUTES
            
            }
            


            Thanks for your help so far, goldsky
              • 11055 ☆ A M B ☆
              • 3,112 Posts
              you’re passing some parameters into the $resultsArray.
              Start investigate:
              ’filter’=>$filter
              ’orderBy’=>$order
                Rico
                Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
                MODx is great, but knowing how to use it well makes it perfect!

                www.virtudraft.com

                Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

                Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

                Maintainter/contributor of Babel

                Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
                • 12578
                • 12 Posts
                Ok, I tried [tt]die($order)[/tt] and [tt]die($filter)[/tt] with no problem - they are strings at this stage and exactly the output I’m expecting:

                die($filter); //duration,100,4
                die($order); //duration DESC, order ASC
                


                The error occurs after [tt]$modx->runSnippet(’Ditto’, $resultsArray);[/tt].

                In the meantime I will change the filter delimiter from "," to something else, maybe the parser is having problems with that, although that wouldn’t explain the inconsistent behaviour.
                  • 12578
                  • 12 Posts
                  Changing the delimiter made no difference. But taking out the delimiter altogether i.e. so we end up with a filter clause string like this: [tt]duration1004[/tt] instead of [tt]duration,100,4[/tt] removes the error.

                  Obviously no results are returned because Ditto’s [tt]&filter[/tt] clause must be: [tt]field,criterion,mode[/tt]
                    • 11055 ☆ A M B ☆
                    • 3,112 Posts
                    try this
                    <?php // highlighting
                    
                    if(is_array($filter)){
                     $filter = implode('\|',$filter);
                    }
                    
                      Rico
                      Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
                      MODx is great, but knowing how to use it well makes it perfect!

                      www.virtudraft.com

                      Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

                      Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

                      Maintainter/contributor of Babel

                      Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
                      • 12578
                      • 12 Posts
                      No change. Still the same error.