in reply to Passing value with two words or more

print $query->redirect("http://webserver/action.asp?name=$name"); Please advise how I can get it to accept more than one word in the form entry for my name field.

URI-encode it. See URI::Escape, CGI's escape and the FAQ How do I decode or create those %-encodings on the web?.

Also, consider learning about the tool you use before you actually use it. You don't seem to know anything about HTTP, but you are using it.

Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

  • Comment on Re: Passing value with two words or more

Replies are listed 'Best First'.
Re: Re: Passing value with two words or more
by hmerrill (Friar) on Mar 11, 2004 at 15:10 UTC
    Three thoughts here.

    First, Juerd is right - you need to properly quote the text contained in $name, and one way to do that is to use URI::Escape.

    Second, for this specific issue, you could get away with simply surrounding $name in the redirect with double quotes, like this:

    print $query->redirect("http://webserver/action.asp?name=\"$name\"" +); OR print $query->redirect(qq!http://webserver/action.asp?name="$name"! +);
    Third, also as Juerd pointed out, and since you've already "use"d CGI, you could use the CGI 'escape' and 'unescape' functions. Read about those either in Lincoln Stein's book 'Official Guide to Programming With CGI.pm' p.199, or by reading the perldocs on the CGI.pm module by doing
    perldoc CGI
    at a command prompt.

    HTH.

      you could get away with simply surrounding $name in the redirect with double quotes

      Care to explain to me why it would then no longer be two words? I can't imagine that this really works. (And if it does, I'd guess it'd be for MSIE only)

      Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

      Thanks all. I tried the escape quotes and it didnt work. I am trying to use the URI::Escape but not sure how to use it. My browser (Netscape 4.77) is the only one that seems to have the problem. The script works with two words when I use IE 5.5 and Netscape 7 but not with Netscape 4.77.