Dear Monks,

I'm writing a CGI form that I want to behave differently based on the value of a URL query string (e.g. http::/localhost/cgi-bin/test_form?url_group=Boston3). Once the form has been filled out, I want to provide a button to let the user start over, while still maintaining the original param from the URL. I have tried using $query->hidden('url_group') to pass the URL param along until the last part of the script in which I have essentially:

my $url_group = $query->param('url_group'); print start_form(-action=>"test_form.pl?$url_group"); print $query->defaults; print end_form;
But this doesn't work. The script just gets called as if $url_group were undefined. Below I have a simple test case:
use strict; use warnings 'all'; use CGI qw(:standard); my $query = CGI->new(); my $url_group; if ($query->param('url_group') =~ m/^(Boston[1|2|3])$/) { $url_group = 'url_group=' . $query->param('url_group'); } print header, start_html; print "<p><b>\$query->param('url_group') = </b>\"" . $query->param('ur +l_group') . "\"</p>"; print p("<b>The value of \$url_group is:</b> $url_group"); print start_form(-action=>"test_form.pl?$url_group"); print $query->defaults("This doesn't pass the group"); print end_form; print end_html; print p("<b><a href=test_form.pl?$url_group>This does work</a></b>") i +f ($url_group);
Even if I refresh the browser with the query string still in the URL, it doesn't get passed the param. (I have to browse the script first *without* the query string, and then browse again *with* the query string, at which point it the param gets used initially.) Interestingly, a *link* to the script using the query string does work...but I'd rather use a button in the real script. Any idea how I can get this to work?


In reply to Can't seem to pass query string with start_form(-action=>"test_form.pl?$url_group") by memnoch

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.