We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38062
    • 6 Posts
    I have good practice always to validate user input but I realised that there is no check if someone entered page number that is out of range or on invalid. Someone can enter in url get-resource-page.html?page=-2 and getPage will render pagination which will result in something like "Page -2 of 5".

    That was pretty easy to correct but I have other problem. Let say that we have total of 5 pages with limit set to 1 (one item per page). Someone can enter get-resource-page.html?page=22 which is the page number which doesnt exist. The thing what I would like to accomplish is to set last page as the current when someone enter url like that, tho problem is that variable $offset is calculated at the begining of the script and it relayed on user input which is bad.

    I ended calling snippet object twice, adding this lines at the start od the code:
    $elementObj = $modx->getObject($properties['elementClass'], array('name' => $properties['element']));
    $output = $elementObj->process($properties);
    $totalSetSafe = $modx->getPlaceholder($properties['totalVar']);


    But now I had some caching problem, and sometimes (dont know why) $totalSetSafe isnt calculated. So my question bould be how can I get total number of resources return by called snippet. My idea was to make custom sql query from that snippet with removed LIMIT and colum names replaced with COUNT(*). Is that possible at all?!

    Thanks in advance!