I have some code, which works on a normal php page. The code snippet created will find the $_GET['retval2'] but no if statements work in the snippet, it defaults to the else.
Was the plain PHP file in the MODX directory? If not, maybe a rewrite rule in the MODX .htaccess file is missing the QSA directive to append the query string. It will still show in the URL, but won't be in the &_GET array.