How should I redirect users in a formmail script?

132 Views Asked by At

So I'm using a basic formmail script. Within the script I'm using a redirect variable. The value of the redirect is something like:

 http://www.mysite.com/NewOLS_GCUK_EN/bling.aspx?BC=GCUK&IBC=CSEE&SIBC=CSEE

When the redirect action happens however, the URL appears in the browser as:

 http://www.mysite.com/NewOLS_GCUK_EN/bling.aspx?BC=GCUK&IBC=CSEE&SIBC=CSEE

You can see the & characters are replaced with &

Is there any way to fix this?

2

There are 2 best solutions below

0
On

Maybe you can edit the script with a string substitution:

$myRedirectURL =~ s/\&/\&/g;

Or perhaps look in the script where the opposite substitution is taking place, and comment out that step.

0
On

HTML::Entities's decode_entities could decode this for you:

$redirect_target = decode_entities($redirect_target);

But passing the destination URL as HTTP argument (e.g. hidden form field) is dangerous (as @Sinan Ünür already said in the comments). Better store the target URL within your script and pass a selector from the form:

if ($selector eq 'home') { $target_url = 'http://www.foo.bar/'; }
elsif ($selector eq 'bling') { $target_url = 'http://www.foo.bar/NewOLS_GCUK_EN/bling.aspx'; }
else {
    $target_url = 'http://www.foo.bar/default.html'; # Fallback/default value
}

Using a Hash would be shorter:

my %targets = {
    home  => 'http://www.foo.bar/',
    bling => '/NewOLS_GCUK_EN/bling.aspx',
};
$target_url = $targets{$selector} || '/default_feedback_thanks.html';