Dear Wanze - your script doesn't work. I hate to bother you on something so trivial, but I'm at my wits' end here.
I use this form to make a Post_variable called 'alias'
<h5>If you know the property ID, type it here.</h5>
<form id="PID"action="[[goThere]]" method="post">
<label for="alias">
Property Id:
</label>
<input type="text" name="alias" id="alias" size="10" />
<br class="clear" />
<div class="form-buttons">
<input type="submit" value="Go" />
</div>
</form>
I pass control, as you see to a snippet. Here's the snippet:
<?php
$alias = $_POST['alias']; //Sanitise later. Still dangerous.
$res = $modx->getObject('modResource',array('alias' => $alias));
if($res && is_object($res)){
$id = $res->get('id');
$modx->sendForward($modx->makeUrl($id));
}else{
//No page with alias $alias was found...
}
A straight copy of your script.
For an incorrect "alias" - I get a page refresh - numerical or alphanumerical alias;
for a correct numerical alias, I get a page refresh;
for a correct alias beginning with alpha characters I get a 503 error, showing the valid url of the page from which the snippet was activated - but not all the time. If the alias is "XXnnnnXX", ie alpha then numbers then alpha, I get a refresh. I only get the 503 if the alias is alpha then numerical AND correct. Weird.
I've played with your script, trying to test it, adding in echos etc. The echos get passed to the address box - (which I have to admit I wasn't expecting), but I just cannot be sure that there is anything being passed from the form to the snippet, except that I get this good (if start with alpha) - 503 error, bad - refresh, behaviour.
I started out with something more elaborate, getting the current context etc, and tried putting in 'abs' and 'full' in the makeUrl call, all to no avail, so eventually cut everything out except your suggestion, and I'm still stuck. As far as I can see it should work. I tried using 'pagetitle' instead of 'alias', and tried using a guaranteed non-reserved word for the Post_variable in case 'alias' meant something to MODx or PHP. No joy.
I'm stuck.
Can you point out my error?
Nic Boyde