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

I am writing a search within result page and this page with carry previous submit query string with hidden value. my question is how could I append the previous query string with new submit query string before the full string send to the result page?

and here is a code:

sub OutputSearchForm { my $oldSearch = $queryStringHash{'q'}; my $searchSelector = CreateSearchSelector(); my $q = $triplets{"Search"}; # The search query, as returned by Goo +gle print <<END_OF_HEADER; <form method=GET action="$scriptName"> <INPUT TYPE=hidden name=hl value=en> <table cellpadding=0 cellspacing=0 width="100%" border=0> <tr> <td width=5>&nbsp;</td> <td align=left><font face="arial,sans-serif"> <input type=hidden name=q value=\"$oldSearch\"> <input type=text name=q size=61 maxlength=256 value=\"$q\"> $searchSelector <nobr> <INPUT type=submit name=sa VALUE="Search&nbsp;within&nbsp;results +"> </nobr> </font></td> <td align=right valign=top></td> </tr> </table> </form> END_OF_HEADER }

Edit by tye

Replies are listed 'Best First'.
(jryan) Carrying form values from submission to submission
by jryan (Vicar) on Oct 09, 2001 at 19:13 UTC
    If you are asking how to add the data from a previous query onto a newer query, it isn't as simple as adding two strings together. You have to write a new form element with the type "hidden", with a name consistant of your previous query, and the value consistant with the previous one. You can do this by hand, by using CGI's param method to get the data, and then printing the hidden element to the browser. Alternatively, you can do it by using modules to do the work for you. CGI has a special "sticky" property that can be turned on; it will carry values with it from submission to submission. Also, you can try CGI::BuildForm, which you might find easier to use. At either rate, good luck, and welcome to the monastery!
Re: Append query string
by CubicSpline (Friar) on Oct 09, 2001 at 18:44 UTC
    This node could use some formatting!

    But if you simply want to append one string to another do this:

    $str1 = "string1"; $str2 = "string2"; $str1 .= $str2; print $str1; =OUTPUT string1string2
Re: how to append query string
by cjensen (Sexton) on Oct 09, 2001 at 21:34 UTC
    Break up your old query string. Create a hidden input for each key/value pair. The names of the hidden inputs need to correspond to the keys from the query string, and the values need to be the values associated with those keys.