Deanimal has asked for the wisdom of the Perl Monks concerning the following question:

Why isn't this printing the URL to the webpage's link? All I get are empty quotes ("").
Thanks,
Dean

Form:
<input type="hidden" name="continue" value="http://www.webmonkeydean.com/et-toi/">

Script:
<a href="$fields{'continue'}">Continue</a>

A little bit more of the script:

if ($ENV{'REQUEST_METHOD'} eq "GET" && -e $DATA_FILE){ $MODE="VIEW"; &set_colors; &process_file; &do_stats; $PAGEHEADER=&set_page_header; $PAGEFOOTER=&set_page_footer; print "Content-type: text/html\n\n"; print "$PAGEHEADER\n"; &display_stats; print "$PAGEFOOTER\n"; exit; } sub set_page_footer{ my $PAGEFOOT=<<__END_PAGE_FOOT__; <TR> <TD COLSPAN=4 ALIGN=CENTER> <FONT FACE="$FONT" COLOR="$FONTCOLOR"> <A HREF="$fields{'continue'}"><B>Continue</B></a> </FONT> </TD> </TR> </TABLE> </td></tr></table> </body> </html> __END_PAGE_FOOT__ return $PAGEFOOT; }

All of the script as a text file:
http://www.webmonkeydean.com/et-toi/survey.txt

The survey in action:
http://www.webmonkeydean.com/et-toi/

Replies are listed 'Best First'.
Re: Printing URL to webpage
by fruiture (Curate) on Nov 06, 2002 at 15:19 UTC

    Probably because your script is more a mess than a Perl Script. $fields{'continue'} may be an empty string, or undef, not even existing in the hash. You won't find out, you haven't even enabled warnings and the strict pragma. Where does %fields come from? Hmm, it's coming from an a Broken CGI Parser...

    Before you go on, read use CGI or die, Idiotic Perl, `perldoc strict`, `perldoc warnings`, `perldoc perlsub` (because you didn't get Perl 5 subroutines), `perldoc perlstyle` (because it helps in general).

    I hope you don't wamnt to spread this "thing" over the web as one could guess from these comments at its beginning. Don't, it is bad.

    --
    http://fruiture.de

      The comments in the code are from bignosedbird.com. They have resources online for learning HTML and other aspects of the web. Their HTML stuff isn't bad, but they are definitely not the place for learning Perl.

      If you absolutely need a script for something off the Internet, don't trust MSA or bignosebird or any generic "learning" sites, because in my experience they slaughter Perl. See: http://nms-cgi.sourceforge.net/

      John J Reiser
      newrisedesigns.com

      fruiture,
      Thanks for pointing me to those articles; I'll study them.

      1. The script is a "mess" because it came that way.
      2. The script is not mine, as you seem to think.
      3. $fields{'continue'} does work for another link in the same script, so I don't understand what you mean when you say it may be empty, undef, or not existing.
Re: (nrd) Printing URL to webpage
by newrisedesigns (Curate) on Nov 06, 2002 at 15:22 UTC

    Use CGI; it will help you accept parameters much more cleanly.

    ...but this is a rolled script from bignosebird.com. Check to make sure "continue" is actually put into the $fields variable (it's not), or, just change the following lines:

    $SHOW_RESULTS=1; # $JUMP_URL="$ENV{'HTTP_REFERER'}"; # $JUMP_URL="$fields{'continue'}"; $JUMP_URL=q[http://www.webmonkeydean.com/et-toi/];

    You are attempting to get the variables before they are even put into the %fields hash. Either move the hashing north (or the $JUMP_URL south) or rewrite it with CGI.pm

    Hope this helps, and good luck to you.

    John J Reiser
    newrisedesigns.com

      Thanks John,

      I don't understand everything you said yet, but I'll study it.

      Here's another question: You told me why this doesn't work; but it does work for the "you already voted" webpage which is printed by the same script. Why does it work for that page but not the "results" page?

        The reason the link works when a user has already voted is because the script isn't using the same variable used in the main page ($fields{continue} instead of $JUMP_URL). This works because the subroutine that prints the "You already voted" message calls yet another subroutine that populates %fields with the proper information (your "continue" hidden field).

        The error doesn't use $JUMP_URL, which is assigned nothing earlier in the script, it uses $fields{continue} which by that time has what you want in it.

        John J Reiser
        newrisedesigns.com

      It sounds like you're saying it's a little more involved than I thought, and I need to actually *learn* Perl (imagine that!) to do what I'm trying to do. Well, I'd like to get the survey to work in the meantime, so I'll stop trying to enter the URL as a variable and instead just hardcode the URL directly into the script. This means I'll have to have a separate script for each survey (I have 2), but at least it will work while I learn how to use the variable.
Re: Printing URL to webpage
by dash2 (Hermit) on Nov 06, 2002 at 17:50 UTC
    Learning perl is good in itself... here's a first step.

    # untested! use CGI; # the standard way of using perl to write web pages my $cgi = new CGI; # creates a new object to use print $cgi->header; # prints out your basic http headers my $continue = $cgi->param('continue'); # get the value of the "contin +ue" parameter passed to your script # print some HTML here... print "<A HREF=\"$continue\"><B>Continue</B></a>"; # some people use C +GI methods to print out HTML, but I am happy doing it raw

    Now go check out the CGI.pm documentation and learn more.

    dave hj~

      Cool! Thanks a lot, dave. I look forward to trying that out. And thanks especially for giving me something to work with other than saying to RTFM.
        I tried it and get the same results. Maybe it has something to do with the way the webpage is generated-- it's a series of pieces that are written in the script separately and then added together. There's a page_header + stats (which are composed of several sections) + page_footer. I'll go read more. Thanks again though,

        Dean
Re: Printing URL to webpage
by fglock (Vicar) on Nov 06, 2002 at 15:19 UTC

    I answered the survey and it worked!

Re: Printing URL to webpage
by Deanimal (Acolyte) on Nov 06, 2002 at 22:32 UTC

    Here's what might work as a way to hard-code multiple surveys into one script. I know it's a little hackish, but I'd like a solution that works sooner rather than waiting several months to learn Perl first (I do have bills to pay; and the website needs to be functional.):

    Replace the line near the top:
    $JUMP_URL="$ENV{'HTTP_REFERER'}";

    with:

    if ($survey_name eq "01howfound"){ $JUMP_URL="http://www.webmonkeydean.com/et-toi/"; } if ($survey_name eq "02swampopera"){ $JUMP_URL="http://www.webmonkeydean.com/et-toi/schedule"; } # repeat for more surveys else{ $JUMP_URL="$ENV{'HTTP_REFERER'}"; }

    And use $JUMP_URL as the links like this:
    <a href="$JUMP_URL">Continue</a>

    (In case you wonder "why not just use '$JUMP_URL="$ENV{'HTTP_REFERER'}";'", it wasn't working sometimes-- possibly because of firewall blocking.)