Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Pushing along the Query_String

by peppiv (Curate)
on Jul 08, 2003 at 12:52 UTC ( [id://272259]=perlquestion: print w/replies, xml ) Need Help??

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

We recently got a new director who's doing R&D for some Internet stuff and he's a bit of an asp lover. After I stopped laughing I set out to show him the power of PERL. So here's our first project - Set up some Google Ad Campaigns and create some web pages promoting one of our new services.

Easy enough. But then I thought, there's got to be a good way to track all these visits by various keywords and campaigns. So they're all pointing to a Perl script that slurps the Query_String (from the Google Ad Campaign) and points the requests to the proper destination. The Query_String is also split into its constituent parts and stuffed into a DB. Good so far. Then I thought I'd like to push along the Query_String to maintain some sort of state and measure the depth of each visit.

There is an initial landing page which I move the Query_String over by:
print "Location: $Landing_1?$ENV{'QUERY_STRING'}&id=$id\n";
Where $Landing_1 is the URL and $id is a timestamp (we're not looking for 100% accuracy).

Viewers have now clicked on a Google Ad Campaign and are peacefully resting on our initial landing page with the Query_String in tow. (eg. http://www.newservice.com/vacation_offer.html?src=google&c=D1&ag=2&kw=discount+family&id=1057667802) Here's where I faulter.

On this page I have a form that requests the user to choose the state she or he lives in. This is required by our legal team because we're not allowed to offer this service to various states. Once they do the drop down menu and submit, and they are welcomed, I relocate them to another page but I'd like to carry over the Query_String. So I tried this:
print "Location: $Landing_2?$ENV{'QUERY_STRING'}\n";
The script accepts the state value with:
my $state = param("state");
And based upon it's condition it is passed to the $Landing_2. But when the $Landing_2 comes up, the Query_String does not follow. $Landing_2 is a short request form. I need them to fill this out and go on to $Landing_3. I would like to push the Query_String along yet again.

What I'm trying to achieve is when I go to $Landing_2, I'd like to bring along the ID so I can Update my DB with this new depth level. And again when I go to $Landing_3.

I am not interested in using Cookies at this point.

My questions boils down to this. Does form submission eradicate the Query_String? If using POST?

peppiv

Replies are listed 'Best First'.
Re: Pushing along the Query_String
by tcf22 (Priest) on Jul 08, 2003 at 13:34 UTC
    If you are using CGI.pm, then there is a way to accept a query string if using a POST. You will need to uncomment a line. Its line 448 in version 2.752.
    # Some people want to have their cake and eat it too! # Uncomment this line to have the contents of the query string # APPENDED to the POST data. # $query_string .= (length($query_string) ? '&' : '') . $ENV{'QUERY_ST +RING'} if defined $ENV{'QUERY_STRING'};
    This will give you access to the CGI params, but if you just want the whole string in $ENV{QUERY_STRING}, then you need to put it in your form tag.
    <FORM method=POST action="test.cgi?$ENV{QUERY_STRING}">

    Then again you could just do something like this.
    <INPUT type="hidden" name="query_string" value="$ENV{QUERY_STRING}">
    Then access it in the next cgi like this
    my $query_string = $cgi->param('query_string');
      Thanks for the help. I didn't want to break into the CGI.pm and make any changes. So I tried you're other two possibilities to no avail. The Google Ad Campaign gets me to the first landing page with this URL:

      http://www.newservice.com/new_offer.html?src=google&c=D1&ag=2&kw=discount+family&id=1057670384

      It's a flat html file with a form in it. When I tried to add the Query_String, it wouldn't accept it's value. I was able to push it along once using JavaScript and the location.search method. But I couldn't get it to read from there.

      Any other ideas are more than welcome!

      peppiv

        It's a flat html file with a form in it.

        Well that's the problem right there. You're either going to have to convert that to an SSI or a cgi script or put a modperl handler on top of it -- you need to jam the incoming query params onto the form so they're passed along.

        -derby

        update: There may be a javascript solution but my brain doesn't even want to go there.

Re: Pushing along the Query_String
by ajdelore (Pilgrim) on Jul 08, 2003 at 19:39 UTC

    You are going to have to make the "landing page" a CGI script. Use this script to build your form, and jam the query string parameters into your form as hidden values.

    This first page would also be a good time to parse the query string and break it into the values you want for the database, rather than passing it untouched and then parsing it in the next script.

    </ajdelore>

      Thanks for all the help. I actually got it to work by using (bows his head in defeat) JavaScript. I made a javascript button for the form submission and used the location.search command combined with document.write to put the query in the form as hidden text.

      peppiv

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://272259]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-03-29 02:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found