private function form_action($matches)
{
// $matches[1] holds single or double quote - whichever was used by webmaster
// $matches[2] holds form submit URL - can be empty which in that case should be replaced with current URL
if (!$matches[2]) {
$matches[2] = $this->base_url;
}
$new_action = proxify_url($matches[2], $this->base_url);
// what is form method?
$form_post = preg_match('@method=(["\'])post\\1@i', $matches[0]) == 1;
// take entire form string - find real url and replace it with proxified url
$result = str_replace($matches[2], $new_action, $matches[0]);
// must be converted to POST otherwise GET form would just start appending name=value pairs to your proxy url
if (!$form_post) {
// may throw Duplicate Attribute warning but only first method matters
$result = str_replace("<form", '<form method="POST"', $result);
// got the idea from Glype - insert this input field to notify proxy later that this form must be converted to GET during http
$result .= '<input type="hidden" name="convertGET" value="1">';
}
return $result;
}