|
|
Question : Perl cgi redirect URL
|
|
I believe this is a pretty basic perl Web code question. Under the popup_menu, I only have one option. When the submit button is pressed, the user should simply be redirected to http://www.rykers.com/SELECTION where selection, in this case, is chris. So, the user should now be at http://www.rykers.com/chris
The commented out code: # -action=>"http://www.rykers.com/" . "chris"
Works...I just want "chris" to be contained in a variable...so the SELECTION will be dynamic.
I'm not real clear on POST and GET...so I've been experiementing with both.
=============================================
#!/usr/local/bin/perl
use CGI;
$co = new CGI;
#$strJumpURL = "http://www.rykers.com"; #print "Location: $strJumpURL\n\n";
print $co->header,
$co->start_html(-title=>'CGI Example'), $co->center($co->h1('Welcome to CGI!')), $co->start_form ( -method=>'GET', # -method=>'POST',
-action=>"http://www.rykers.com/" . $co->param('myuser') # -action=>"http://www.rykers.com/" . "chris" ),
$co->center( $co->popup_menu ( -name=>'myuser', -values=>['chris'] ), $co->submit('Submit'), ),
$co->end_form, $co->end_html; ~
|
Answer : Perl cgi redirect URL
|
|
Gah, I typed all this in before and went and crashed my browser submitting it - so here goes v2.
Short answer is the param('myuser') is not set until you submit the form, so what you are inadvertantly doing is trying to build the form action before you have submitted it. You follow?
Try this 2 file solution:
[form.htm]
[redirect.pl]
#!/usr/local/bin/perl
use CGI;
$co = new CGI;
$user = $co->param('myuser');
$url = 'http://www.mydomain.com/' . $user
print "Location: $url\n\n";
If you want a single file, you must test for the existance of param('myuser') and redirect OR draw the form, and the form's action must call itself - so the 1st time it is called it draws the form, then when you submit, it redirects.
FYI: Post variables are sent with the headers and pretty much invisible to the bog-standard internet user. GET variables are appended to the querystring like redirect.pl?muyser=chris&submit=REDIRECT
It makes very little to CGI's param() routine which method you use.
Mike
|
|
|
|
|