Quote from: kudolink
$param = '';
foreach ($_GET as $key => $value) {
$param .= '&' . $key . '=' . $value;
}
$gets = substr($param, 1);
$output = '?'.$gets;
return $output;
That might well work but you could run into trouble when you turn off friendly urls. If you bother making a snippet for it you should make sure it works in all cases, for all urls like 1.html and index.php?id=1 or index.php?req=1.html otherwise you might end up with a query string like this index.php?id=15&id=39. You might also want to kill the q=3.html which is generated by the rewrite for friendly urls, just in case. And eh,.. what about the hardcoded urls? You should really use [~3~] (or whatever the id of the page you’re linking to is.
Here’s one way to do it.
Create a new snippet called passGets and paste the code below (without the <?php and ?> tags);
<?php
#snippet passGets
//if no url then use current page (use any page you want instead)
$url = isset($pageId)?$modx->makeUrl($pageId):$modx->makeUrl(1);
//make a copy of $_GET so we don't destory anything
$qry = $_GET;
//remove sensitive vars
unset($qry['id'],$qry['q']); //add any others that you might want to strip
//create new query string
array_walk($qry,create_function ('&$v,$k','$v="$k=$v";'));
$qry = @implode('&', $qry);
if($qry) $url .= (strstr($url,'?'))?'&':'?';
return $url .$qry;
?>
Now when you create the links use a snippet call in this format:
<a href="[[passGets? &pageId=`1`]]">Go to page 1 of the set</a>
<a href="[[passGets? &pageId=`2`]]">Go to page 2 of the set</a>
<a href="[[passGets? &pageId=`3`]]">Go to page 3 of the set</a>
where 1, 2 and 3 are the actual id numbers of the page (which you can find in the document tree).
This will work regardless if you have friendly urls on or not..
Hope this helps
Oops,.. you might want to use the [!passGets ...!] variant instead so they don’t get cached.