Following from my
earlier post about IIS 6 being unable to maintain POST data when setting custom error handlers for 404 and 405 errors so that Friendly URLs can be enabled I’m looking at a possible workaround.
The issue is that with FURLs enabled is that I can’t login with WebLogin or submit the standard contact form that comes with the MODx sample site with the default install because the values posted are not maintained through the custom 404 handler on IIS 6.
I set up a test page with a short snippet which outputs a Form with a single text field that submits back to the test page and writes out all values in the $_POST array.
<?php
$form = '<form name="form1" method="post" action="[~[*id*]~]">';
$form.= '<input name="myfield" type="text" value="test text">';
$form.= '<input name="" type="submit" value="Submit">';
$form.= '</form>';
echo $form;
$time = date("d/m/y : H:i:s", time()) ;
$output = "Output: ".$time."n";
foreach($_POST as $key_name => $key_value) {
$output.= $key_name . " = " . $key_value . "<br>";
}
return $output;
?>
With FURLs on nothing is written out due to the IIS 6 issue described above but if I recreate the $_POST array by adding the code below at Line 1 of the Snippet it will output whatever is submitted via the text field:
<?php
$rebuiltPost = array();
parse_str(file_get_contents("php://input"),$rebuiltPost);
$_POST = $rebuiltPost;
?>
With this working I added the Snippet to the main site template right at the top before the DOCTYPE declaration:
[!preservePOST!]
<!DOCTYPE...
Now I can login and submit the contact form successfully.
My query is this – can anyone see any reason why this could be a bad idea or if it will interfere with any other part of MODx? To start with I added the $rebuiltPost code to the config.inc.php as a quick and dirty way to test it but I found that when editing Snippets through the manager it added a backslash in front of single and double quote characters.
I intend to tidy the code up a little by adding a condition so that it will only run if the current page is running off a 404 error. Not sure that this will matter but I guess safer to add it.
Thoughts and comments please.