Re: passing parameters through html documents

dba@althingi.is
Thu, 7 Mar 1996 15:23:56 GMT


From: dba@althingi.is
Date: Thu, 7 Mar 1996 15:23:56 GMT
Message-Id: <199603071523.PAA22473@freki.althingi.is>
To: www-html@w3.org
Subject: Re: passing parameters through html documents


Nobody has yet responded to my earlier query.
I have however noticed a way in which I can pass parameters
through a html document to the script that it invokes at least
using Netscape and Mosaic but not HotJava 
there are environment variables:

HTTP_REFERER
REFERER_URl 

both contain the link reference that the browser came from
(but in Mosaic this is lost upon Reload)

I have therefore changed the cgi-lib.pl function
it has solved my inhouse problem
and I would like to have comments on this:

sub ReadParse {
  local (*in) = @_ if @_;
##local ($i, $key, $val); # replaced by new code line
  local ($i, $key, $val, $ex, $x);
  
  # Read in text
  if (&MethGet) {
    $in = $ENV{'QUERY_STRING'};
  } elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
    read(STDIN,$in,$ENV{'CONTENT_LENGTH'});   
  }
   
  @in = split(/&/,$in);
############################### new code insert start
  $ex = $ENV{'REFERER_URL'};
  if ($ex) {  
    ($x,$ex) = split(/#/,$ex);
    if ($ex) {
        push(@in,split(/&/,$ex));
    }
  }  
############################### new code insert end
  foreach $i (0 .. $#in) {
    # Convert plus's to spaces
    $in[$i] =~ s/\+/ /g;
    
    # Split into key and value.
    ($key, $val) = split(/=/,$in[$i],2); # splits on the first =.
 
    # Convert %XX from hex numbers to alphanumeric
    $key =~ s/%(..)/pack("c",hex($1))/ge;
    $val =~ s/%(..)/pack("c",hex($1))/ge;
    
    # Associate key and value
    $in{$key} .= "\0" if (defined($in{$key})); # \0 is the multiple separator
    $in{$key} .= $val;
    
  }
##return length($in); # replaced by new code line
  return length($in)+length($ex);
}
> From root Mon Mar  4 11:15 PST 1996
> >Received: from www19.w3.org 
> 	by muninn.althingi.is (SMI-8.6/ISnet/11-02-92); Mon, 4 Mar 1996 11:15:33 GMT
> Resent-Date: Mon, 4 Mar 1996 05:53:08 -0500
> Resent-Message-Id: <199603041053.FAA06992@www19.w3.org>
> From: dba@althingi.is
> Date: Mon, 4 Mar 1996 10:51:18 GMT
> To: www-html@w3.org
> Subject: passing parameters through html documents
> X-Sun-Charset: US-ASCII
> Resent-From: www-html@w3.org
> X-Mailing-List: <www-html@w3.org> archive/latest/2697
> X-Loop: www-html@w3.org
> Sender: www-html-request@w3.org
> Resent-Sender: www-html-request@w3.org
> Content-Type: text
> Content-Length: 1029
> 
> I would like to be able to have a link in my document-1 like:
> 
> <a href="document-2.html#field1=value1">...
> 
> Document-2 might be a form or contain a reference
> to a cgi script like:
> 
> <a href="myscript.pl&field2=value2">...
> 
> but the script would actually receive:
> 
> QUERY_STRING=feild1=value1&field2=value2
> 
> In this way the input data could be accumulated
> from several list choices. I frequently have a general
> script to look up a database but find my self
> in a position where I either have to have several
> different forms all with a different hidden field value
> or I can use a single form but have to ask the user 
> to fill in a field which only has one logical value 
> in the situation.
> 
> Sorry if this idea has already been discussed
> or if there is a more elegant solution
> I would be greatful if somebody pointed me to it.
> 
-- 
Thorvaldur Gunnlaugsson       \           The Parliament of Iceland
thg@althingi.is                \         comp. departm.  Vonarstr 8
voice:3554-5630655 fax:5630670   \                     150 REYKJAVIK