home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3 / perl5 / CGI.z / CGI
Encoding:
Text File  |  1998-10-30  |  111.4 KB  |  2,773 lines

  1.  
  2.  
  3.  
  4. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      CGI - Simple Common Gateway Interface Class
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.        use CGI;
  13.        # the rest is too complicated for a synopsis; keep reading
  14.  
  15.  
  16. AAAABBBBSSSSTTTTRRRRAAAACCCCTTTT
  17.      This perl library uses perl5 objects to make it easy to create Web fill-
  18.      out forms and parse their contents.  This package defines CGI objects,
  19.      entities that contain the values of the current query string and other
  20.      state variables.  Using a CGI object's methods, you can examine keywords
  21.      and parameters passed to your script, and create forms whose initial
  22.      values are taken from the current query (thereby preserving state
  23.      information).
  24.  
  25.      The current version of CGI.pm is available at
  26.  
  27.        http://www.genome.wi.mit.edu/ftp/pub/software/WWW/cgi_docs.html
  28.        ftp://ftp-genome.wi.mit.edu/pub/software/WWW/
  29.  
  30.  
  31. IIIINNNNSSSSTTTTAAAALLLLLLLLAAAATTTTIIIIOOOONNNN
  32.      CGI is a part of the base Perl installation.  However, you may need to
  33.      install a newer version someday.  Therefore:
  34.  
  35.      To install this package, just change to the directory in which this file
  36.      is found and type the following:
  37.  
  38.              perl Makefile.PL
  39.              make
  40.              make install
  41.  
  42.      This will copy CGI.pm to your perl library directory for use by all perl
  43.      scripts.  You probably must be root to do this.   Now you can load the
  44.      CGI routines in your Perl scripts with the line:
  45.  
  46.              use CGI;
  47.  
  48.      If you don't have sufficient privileges to install CGI.pm in the Perl
  49.      library directory, you can put CGI.pm into some convenient spot, such as
  50.      your home directory, or in cgi-bin itself and prefix all Perl scripts
  51.      that call it with something along the lines of the following preamble:
  52.  
  53.              use lib '/home/davis/lib';
  54.              use CGI;
  55.  
  56.      If you are using a version of perl earlier than 5.002 (such as NT perl),
  57.      use this instead:
  58.  
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  71.  
  72.  
  73.  
  74.              BEGIN {
  75.                      unshift(@INC,'/home/davis/lib');
  76.              }
  77.              use CGI;
  78.  
  79.      The CGI distribution also comes with a cute module called the _C_G_I::_C_a_r_p
  80.      manpage.  It redefines the _d_i_e(), _w_a_r_n(), _c_o_n_f_e_s_s() and _c_r_o_a_k() error
  81.      routines so that they write nicely formatted error messages into the
  82.      server's error log (or to the output stream of your choice).  This avoids
  83.      long hours of groping through the error and access logs, trying to figure
  84.      out which CGI script is generating  error messages.  If you choose, you
  85.      can even have fatal error messages echoed to the browser to avoid the
  86.      annoying and uninformative "Server Error" message.
  87.  
  88. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  89.      CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA NNNNEEEEWWWW QQQQUUUUEEEERRRRYYYY OOOOBBBBJJJJEEEECCCCTTTT::::
  90.  
  91.           $query = new CGI;
  92.  
  93.      This will parse the input (from both POST and GET methods) and store it
  94.      into a perl5 object called $query.
  95.  
  96.      CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA NNNNEEEEWWWW QQQQUUUUEEEERRRRYYYY OOOOBBBBJJJJEEEECCCCTTTT FFFFRRRROOOOMMMM AAAANNNN IIIINNNNPPPPUUUUTTTT FFFFIIIILLLLEEEE
  97.  
  98.           $query = new CGI(INPUTFILE);
  99.  
  100.      If you provide a file handle to the _n_e_w() method, it will read parameters
  101.      from the file (or STDIN, or whatever).  The file can be in any of the
  102.      forms describing below under debugging (i.e. a series of newline
  103.      delimited TAG=VALUE pairs will work).  Conveniently, this type of file is
  104.      created by the _s_a_v_e() method (see below).  Multiple records can be saved
  105.      and restored.
  106.  
  107.      Perl purists will be pleased to know that this syntax accepts references
  108.      to file handles, or even references to filehandle globs, which is the
  109.      "official" way to pass a filehandle:
  110.  
  111.          $query = new CGI(\*STDIN);
  112.  
  113.      You can also initialize the query object from an associative array
  114.      reference:
  115.  
  116.          $query = new CGI( {'dinosaur'=>'barney',
  117.                             'song'=>'I love you',
  118.                             'friends'=>[qw/Jessica George Nancy/]}
  119.                          );
  120.  
  121.      or from a properly formatted, URL-escaped query string:
  122.  
  123.          $query = new CGI('dinosaur=barney&color=purple');
  124.  
  125.      To create an empty query, initialize it from an empty string or hash:
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  137.  
  138.  
  139.  
  140.              $empty_query = new CGI("");
  141.                   -or-
  142.              $empty_query = new CGI({});
  143.  
  144.  
  145.      FFFFEEEETTTTCCCCHHHHIIIINNNNGGGG AAAA LLLLIIIISSSSTTTT OOOOFFFF KKKKEEEEYYYYWWWWOOOORRRRDDDDSSSS FFFFRRRROOOOMMMM TTTTHHHHEEEE QQQQUUUUEEEERRRRYYYY::::
  146.  
  147.           @keywords = $query->keywords
  148.  
  149.      If the script was invoked as the result of an <ISINDEX> search, the
  150.      parsed keywords can be obtained as an array using the _k_e_y_w_o_r_d_s() method.
  151.  
  152.      FFFFEEEETTTTCCCCHHHHIIIINNNNGGGG TTTTHHHHEEEE NNNNAAAAMMMMEEEESSSS OOOOFFFF AAAALLLLLLLL TTTTHHHHEEEE PPPPAAAARRRRAAAAMMMMEEEETTTTEEEERRRRSSSS PPPPAAAASSSSSSSSEEEEDDDD TTTTOOOO YYYYOOOOUUUURRRR SSSSCCCCRRRRIIIIPPPPTTTT::::
  153.  
  154.           @names = $query->param
  155.  
  156.      If the script was invoked with a parameter list (e.g.
  157.      "name1=value1&name2=value2&name3=value3"), the _p_a_r_a_m() method will return
  158.      the parameter names as a list.  If the script was invoked as an <ISINDEX>
  159.      script, there will be a single parameter named 'keywords'.
  160.  
  161.      NOTE: As of version 1.5, the array of parameter names returned will be in
  162.      the same order as they were submitted by the browser.  Usually this order
  163.      is the same as the order in which the parameters are defined in the form
  164.      (however, this isn't part of the spec, and so isn't guaranteed).
  165.  
  166.      FFFFEEEETTTTCCCCHHHHIIIINNNNGGGG TTTTHHHHEEEE VVVVAAAALLLLUUUUEEEE OOOORRRR VVVVAAAALLLLUUUUEEEESSSS OOOOFFFF AAAA SSSSIIIINNNNGGGGLLLLEEEE NNNNAAAAMMMMEEEEDDDD PPPPAAAARRRRAAAAMMMMEEEETTTTEEEERRRR::::
  167.  
  168.          @values = $query->param('foo');
  169.  
  170.                    -or-
  171.  
  172.          $value = $query->param('foo');
  173.  
  174.      Pass the _p_a_r_a_m() method a single argument to fetch the value of the named
  175.      parameter. If the parameter is multivalued (e.g. from multiple selections
  176.      in a scrolling list), you can ask to receive an array.  Otherwise the
  177.      method will return a single value.
  178.  
  179.      SSSSEEEETTTTTTTTIIIINNNNGGGG TTTTHHHHEEEE _V_A_L_U_E(S) OF A NAMED PARAMETER:
  180.  
  181.          $query->param('foo','an','array','of','values');
  182.  
  183.      This sets the value for the named parameter 'foo' to an array of values.
  184.      This is one way to change the value of a field AFTER the script has been
  185.      invoked once before.  (Another way is with the -override parameter
  186.      accepted by all methods that generate form elements.)
  187.  
  188.      _p_a_r_a_m() also recognizes a named parameter style of calling described in
  189.      more detail later:
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  203.  
  204.  
  205.  
  206.          $query->param(-name=>'foo',-values=>['an','array','of','values']);
  207.  
  208.                                    -or-
  209.  
  210.          $query->param(-name=>'foo',-value=>'the value');
  211.  
  212.  
  213.      AAAAPPPPPPPPEEEENNNNDDDDIIIINNNNGGGG AAAADDDDDDDDIIIITTTTIIIIOOOONNNNAAAALLLL VVVVAAAALLLLUUUUEEEESSSS TTTTOOOO AAAA NNNNAAAAMMMMEEEEDDDD PPPPAAAARRRRAAAAMMMMEEEETTTTEEEERRRR::::
  214.  
  215.         $query->append(-name=>;'foo',-values=>['yet','more','values']);
  216.  
  217.      This adds a value or list of values to the named parameter.  The values
  218.      are appended to the end of the parameter if it already exists.  Otherwise
  219.      the parameter is created.  Note that this method only recognizes the
  220.      named argument calling syntax.
  221.  
  222.      IIIIMMMMPPPPOOOORRRRTTTTIIIINNNNGGGG AAAALLLLLLLL PPPPAAAARRRRAAAAMMMMEEEETTTTEEEERRRRSSSS IIIINNNNTTTTOOOO AAAA NNNNAAAAMMMMEEEESSSSPPPPAAAACCCCEEEE::::
  223.  
  224.         $query->import_names('R');
  225.  
  226.      This creates a series of variables in the 'R' namespace.  For example,
  227.      $R::foo, @R:foo.  For keyword lists, a variable @R::keywords will appear.
  228.      If no namespace is given, this method will assume 'Q'.  WARNING:  don't
  229.      import anything into 'main'; this is a major security risk!!!!
  230.  
  231.      In older versions, this method was called iiiimmmmppppoooorrrrtttt(((()))).  As of version 2.20,
  232.      this name has been removed completely to avoid conflict with the built-in
  233.      Perl module iiiimmmmppppoooorrrrtttt operator.
  234.  
  235.      DDDDEEEELLLLEEEETTTTIIIINNNNGGGG AAAA PPPPAAAARRRRAAAAMMMMEEEETTTTEEEERRRR CCCCOOOOMMMMPPPPLLLLEEEETTTTEEEELLLLYYYY::::
  236.  
  237.          $query->delete('foo');
  238.  
  239.      This completely clears a parameter.  It sometimes useful for resetting
  240.      parameters that you don't want passed down between script invocations.
  241.  
  242.      DDDDEEEELLLLEEEETTTTIIIINNNNGGGG AAAALLLLLLLL PPPPAAAARRRRAAAAMMMMEEEETTTTEEEERRRRSSSS::::
  243.  
  244.      $query->_d_e_l_e_t_e__a_l_l();
  245.  
  246.      This clears the CGI object completely.  It might be useful to ensure that
  247.      all the defaults are taken when you create a fill-out form.
  248.  
  249.      SSSSAAAAVVVVIIIINNNNGGGG TTTTHHHHEEEE SSSSTTTTAAAATTTTEEEE OOOOFFFF TTTTHHHHEEEE FFFFOOOORRRRMMMM TTTTOOOO AAAA FFFFIIIILLLLEEEE::::
  250.  
  251.          $query->save(FILEHANDLE)
  252.  
  253.      This will write the current state of the form to the provided filehandle.
  254.      You can read it back in by providing a filehandle to the _n_e_w() method.
  255.      Note that the filehandle can be a file, a pipe, or whatever!
  256.  
  257.  
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  269.  
  270.  
  271.  
  272.      The format of the saved file is:
  273.  
  274.              NAME1=VALUE1
  275.              NAME1=VALUE1'
  276.              NAME2=VALUE2
  277.              NAME3=VALUE3
  278.              =
  279.  
  280.      Both name and value are URL escaped.  Multi-valued CGI parameters are
  281.      represented as repeated names.  A session record is delimited by a single
  282.      = symbol.  You can write out multiple records and read them back in with
  283.      several calls to nnnneeeewwww.  You can do this across several sessions by opening
  284.      the file in append mode, allowing you to create primitive guest books, or
  285.      to keep a history of users' queries.  Here's a short example of creating
  286.      multiple session records:
  287.  
  288.         use CGI;
  289.  
  290.         open (OUT,">>test.out") || die;
  291.         $records = 5;
  292.         foreach (0..$records) {
  293.             my $q = new CGI;
  294.             $q->param(-name=>'counter',-value=>$_);
  295.             $q->save(OUT);
  296.         }
  297.         close OUT;
  298.  
  299.         # reopen for reading
  300.         open (IN,"test.out") || die;
  301.         while (!eof(IN)) {
  302.             my $q = new CGI(IN);
  303.             print $q->param('counter'),"\n";
  304.         }
  305.  
  306.      The file format used for save/restore is identical to that used by the
  307.      Whitehead Genome Center's data exchange format "Boulderio", and can be
  308.      manipulated and even databased using Boulderio utilities.  See
  309.        http://www.genome.wi.mit.edu/genome_software/other/boulder.html
  310.  
  311.      for further details.
  312.  
  313.      CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA SSSSEEEELLLLFFFF----RRRREEEEFFFFEEEERRRREEEENNNNCCCCIIIINNNNGGGG UUUURRRRLLLL TTTTHHHHAAAATTTT PPPPRRRREEEESSSSEEEERRRRVVVVEEEESSSS SSSSTTTTAAAATTTTEEEE IIIINNNNFFFFOOOORRRRMMMMAAAATTTTIIIIOOOONNNN::::
  314.  
  315.          $myself = $query->self_url;
  316.          print "<A HREF=$myself>I'm talking to myself.</A>";
  317.  
  318.      _s_e_l_f__u_r_l() will return a URL, that, when selected, will reinvoke this
  319.      script with all its state information intact.  This is most useful when
  320.      you want to jump around within the document using internal anchors but
  321.      you don't want to disrupt the current contents of the _f_o_r_m(s).  Something
  322.      like this will do the trick.
  323.  
  324.  
  325.  
  326.  
  327.                                                                         PPPPaaaaggggeeee 5555
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  335.  
  336.  
  337.  
  338.           $myself = $query->self_url;
  339.           print "<A HREF=$myself#table1>See table 1</A>";
  340.           print "<A HREF=$myself#table2>See table 2</A>";
  341.           print "<A HREF=$myself#yourself>See for yourself</A>";
  342.  
  343.      If you don't want to get the whole query string, call the method _u_r_l() to
  344.      return just the URL for the script:
  345.  
  346.          $myself = $query->url;
  347.          print "<A HREF=$myself>No query string in this baby!</A>\n";
  348.  
  349.      You can also retrieve the unprocessed query string with _q_u_e_r_y__s_t_r_i_n_g():
  350.  
  351.          $the_string = $query->query_string;
  352.  
  353.  
  354.      CCCCOOOOMMMMPPPPAAAATTTTIIIIBBBBIIIILLLLIIIITTTTYYYY WWWWIIIITTTTHHHH CCCCGGGGIIII----LLLLIIIIBBBB....PPPPLLLL
  355.  
  356.      To make it easier to port existing programs that use cgi-lib.pl the
  357.      compatibility routine "ReadParse" is provided.  Porting is simple:
  358.  
  359.      OLD VERSION
  360.          require "cgi-lib.pl";
  361.          &ReadParse;
  362.          print "The value of the antique is $in{antique}.\n";
  363.  
  364.      NEW VERSION
  365.          use CGI;
  366.          CGI::ReadParse
  367.          print "The value of the antique is $in{antique}.\n";
  368.  
  369.      CGI.pm's _R_e_a_d_P_a_r_s_e() routine creates a tied variable named %in, which can
  370.      be accessed to obtain the query variables.  Like ReadParse, you can also
  371.      provide your own variable.  Infrequently used features of ReadParse, such
  372.      as the creation of @in and $in variables, are not supported.
  373.  
  374.      Once you use ReadParse, you can retrieve the query object itself this
  375.      way:
  376.  
  377.          $q = $in{CGI};
  378.          print $q->textfield(-name=>'wow',
  379.                              -value=>'does this really work?');
  380.  
  381.      This allows you to start using the more interesting features of CGI.pm
  382.      without rewriting your old scripts from scratch.
  383.  
  384.      CCCCAAAALLLLLLLLIIIINNNNGGGG CCCCGGGGIIII FFFFUUUUNNNNCCCCTTTTIIIIOOOONNNNSSSS TTTTHHHHAAAATTTT TTTTAAAAKKKKEEEE MMMMUUUULLLLTTTTIIIIPPPPLLLLEEEE AAAARRRRGGGGUUUUMMMMEEEENNNNTTTTSSSS
  385.  
  386.      In versions of CGI.pm prior to 2.0, it could get difficult to remember
  387.      the proper order of arguments in CGI function calls that accepted five or
  388.      six different arguments.  As of 2.0, there's a better way to pass
  389.      arguments to the various CGI functions.  In this style, you pass a series
  390.  
  391.  
  392.  
  393.                                                                         PPPPaaaaggggeeee 6666
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  401.  
  402.  
  403.  
  404.      of name=>argument pairs, like this:
  405.  
  406.         $field = $query->radio_group(-name=>'OS',
  407.                                      -values=>[Unix,Windows,Macintosh],
  408.                                      -default=>'Unix');
  409.  
  410.      The advantages of this style are that you don't have to remember the
  411.      exact order of the arguments, and if you leave out a parameter, in most
  412.      cases it will default to some reasonable value.  If you provide a
  413.      parameter that the method doesn't recognize, it will usually do something
  414.      useful with it, such as incorporating it into the HTML form tag.  For
  415.      example if Netscape decides next week to add a new JUSTIFICATION
  416.      parameter to the text field tags, you can start using the feature without
  417.      waiting for a new version of CGI.pm:
  418.  
  419.         $field = $query->textfield(-name=>'State',
  420.                                    -default=>'gaseous',
  421.                                    -justification=>'RIGHT');
  422.  
  423.      This will result in an HTML tag that looks like this:
  424.  
  425.              <INPUT TYPE="textfield" NAME="State" VALUE="gaseous"
  426.                     JUSTIFICATION="RIGHT">
  427.  
  428.      Parameter names are case insensitive: you can use -name, or -Name or
  429.      -NAME.  You don't have to use the hyphen if you don't want to.  After
  430.      creating a CGI object, call the uuuusssseeee____nnnnaaaammmmeeeedddd____ppppaaaarrrraaaammmmeeeetttteeeerrrrssss(((()))) method with a
  431.      nonzero value.  This will tell CGI.pm that you intend to use named
  432.      parameters exclusively:
  433.  
  434.         $query = new CGI;
  435.         $query->use_named_parameters(1);
  436.         $field = $query->radio_group('name'=>'OS',
  437.                                      'values'=>['Unix','Windows','Macintosh'],
  438.                                      'default'=>'Unix');
  439.  
  440.      Actually, CGI.pm only looks for a hyphen in the first parameter.  So you
  441.      can leave it off subsequent parameters if you like.  Something to be wary
  442.      of is the potential that a string constant like "values" will collide
  443.      with a keyword (and in fact it does!) While Perl usually figures out when
  444.      you're referring to a function and when you're referring to a string, you
  445.      probably should put quotation marks around all string constants just to
  446.      play it safe.
  447.  
  448.      CCCCRRRREEEEAAAATTTTIIIINNNNGGGG TTTTHHHHEEEE HHHHTTTTTTTTPPPP HHHHEEEEAAAADDDDEEEERRRR::::
  449.  
  450.              print $query->header;
  451.  
  452.                   -or-
  453.  
  454.              print $query->header('image/gif');
  455.  
  456.  
  457.  
  458.  
  459.                                                                         PPPPaaaaggggeeee 7777
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  467.  
  468.  
  469.  
  470.                   -or-
  471.  
  472.              print $query->header('text/html','204 No response');
  473.  
  474.                   -or-
  475.  
  476.              print $query->header(-type=>'image/gif',
  477.                                   -nph=>1,
  478.                                   -status=>'402 Payment required',
  479.                                   -expires=>'+3d',
  480.                                   -cookie=>$cookie,
  481.                                   -Cost=>'$2.00');
  482.  
  483.      _h_e_a_d_e_r() returns the Content-type: header.  You can provide your own MIME
  484.      type if you choose, otherwise it defaults to text/html.  An optional
  485.      second parameter specifies the status code and a human-readable message.
  486.      For example, you can specify 204, "No response" to create a script that
  487.      tells the browser to do nothing at all.  If you want to add additional
  488.      fields to the header, just tack them on to the end:
  489.  
  490.          print $query->header('text/html','200 OK','Content-Length: 3002');
  491.  
  492.      The last example shows the named argument style for passing arguments to
  493.      the CGI methods using named parameters.  Recognized parameters are ----ttttyyyyppppeeee,
  494.      ----ssssttttaaaattttuuuussss, ----eeeexxxxppppiiiirrrreeeessss, and ----ccccooooooookkkkiiiieeee.  Any other parameters will be stripped of
  495.      their initial hyphens and turned into header fields, allowing you to
  496.      specify any HTTP header you desire.
  497.  
  498.      Most browsers will not cache the output from CGI scripts.  Every time the
  499.      browser reloads the page, the script is invoked anew.  You can change
  500.      this behavior with the ----eeeexxxxppppiiiirrrreeeessss parameter.  When you specify an absolute
  501.      or relative expiration interval with this parameter, some browsers and
  502.      proxy servers will cache the script's output until the indicated
  503.      expiration date.  The following forms are all valid for the -expires
  504.      field:
  505.  
  506.              +30s                              30 seconds from now
  507.              +10m                              ten minutes from now
  508.              +1h                               one hour from now
  509.              -1d                               yesterday (i.e. "ASAP!")
  510.              now                               immediately
  511.              +3M                               in three months
  512.              +10y                              in ten years time
  513.              Thursday, 25-Apr-96 00:40:33 GMT  at the indicated time & date
  514.  
  515.      (_C_G_I::_e_x_p_i_r_e_s() is the static function call used internally that turns
  516.      relative time intervals into HTTP dates.  You can call it directly if you
  517.      wish.)
  518.  
  519.      The ----ccccooooooookkkkiiiieeee parameter generates a header that tells the browser to
  520.      provide a "magic cookie" during all subsequent transactions with your
  521.      script.  Netscape cookies have a special format that includes interesting
  522.  
  523.  
  524.  
  525.                                                                         PPPPaaaaggggeeee 8888
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  533.  
  534.  
  535.  
  536.      attributes such as expiration time.  Use the _c_o_o_k_i_e() method to create
  537.      and retrieve session cookies.
  538.  
  539.      The ----nnnnpppphhhh parameter, if set to a true value, will issue the correct
  540.      headers to work with a NPH (no-parse-header) script.  This is important
  541.      to use with certain servers, such as Microsoft Internet Explorer, which
  542.      expect all their scripts to be NPH.
  543.  
  544.      GGGGEEEENNNNEEEERRRRAAAATTTTIIIINNNNGGGG AAAA RRRREEEEDDDDIIIIRRRREEEECCCCTTTTIIIIOOOONNNN IIIINNNNSSSSTTTTRRRRUUUUCCCCTTTTIIIIOOOONNNN
  545.  
  546.         print $query->redirect('http://somewhere.else/in/movie/land');
  547.  
  548.      redirects the browser elsewhere.  If you use redirection like this, you
  549.      should nnnnooootttt print out a header as well.  As of version 2.0, we produce
  550.      both the unofficial Location: header and the official URI:  header.  This
  551.      should satisfy most servers and browsers.
  552.  
  553.      One hint I can offer is that relative links may not work correctly when
  554.      you generate a redirection to another document on your site.  This is due
  555.      to a well-intentioned optimization that some servers use.  The solution
  556.      to this is to use the full URL (including the http: part) of the document
  557.      you are redirecting to.
  558.  
  559.      You can use named parameters:
  560.  
  561.          print $query->redirect(-uri=>'http://somewhere.else/in/movie/land',
  562.                                 -nph=>1);
  563.  
  564.      The ----nnnnpppphhhh parameter, if set to a true value, will issue the correct
  565.      headers to work with a NPH (no-parse-header) script.  This is important
  566.      to use with certain servers, such as Microsoft Internet Explorer, which
  567.      expect all their scripts to be NPH.
  568.  
  569.      CCCCRRRREEEEAAAATTTTIIIINNNNGGGG TTTTHHHHEEEE HHHHTTTTMMMMLLLL HHHHEEEEAAAADDDDEEEERRRR::::
  570.  
  571.         print $query->start_html(-title=>'Secrets of the Pyramids',
  572.                                  -author=>'fred@capricorn.org',
  573.                                  -base=>'true',
  574.                                  -target=>'_blank',
  575.                                  -meta=>{'keywords'=>'pharaoh secret mummy',
  576.                                          'copyright'=>'copyright 1996 King Tut'},
  577.                                  -style=>{'src'=>'/styles/style1.css'},
  578.                                  -BGCOLOR=>'blue');
  579.  
  580.         -or-
  581.  
  582.         print $query->start_html('Secrets of the Pyramids',
  583.                                  'fred@capricorn.org','true',
  584.                                  'BGCOLOR="blue"');
  585.  
  586.      This will return a canned HTML header and the opening <BODY> tag. All
  587.      parameters are optional.   In the named parameter form, recognized
  588.  
  589.  
  590.  
  591.                                                                         PPPPaaaaggggeeee 9999
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  599.  
  600.  
  601.  
  602.      parameters are -title, -author, -base, -xbase and -target (see below for
  603.      the explanation).  Any additional parameters you provide, such as the
  604.      Netscape unofficial BGCOLOR attribute, are added to the <BODY> tag.
  605.  
  606.      The argument ----xxxxbbbbaaaasssseeee allows you to provide an HREF for the <BASE> tag
  607.      different from the current location, as in
  608.  
  609.          -xbase=>"http://home.mcom.com/"
  610.  
  611.      All relative links will be interpreted relative to this tag.
  612.  
  613.      The argument ----ttttaaaarrrrggggeeeetttt allows you to provide a default target frame for all
  614.      the links and fill-out forms on the page.  See the Netscape documentation
  615.      on frames for details of how to manipulate this.
  616.  
  617.          -target=>"answer_window"
  618.  
  619.      All relative links will be interpreted relative to this tag.  You add
  620.      arbitrary meta information to the header with the ----mmmmeeeettttaaaa argument.  This
  621.      argument expects a reference to an associative array containing
  622.      name/value pairs of meta information.  These will be turned into a series
  623.      of header <META> tags that look something like this:
  624.  
  625.          <META NAME="keywords" CONTENT="pharaoh secret mummy">
  626.          <META NAME="description" CONTENT="copyright 1996 King Tut">
  627.  
  628.      There is no support for the HTTP-EQUIV type of <META> tag.  This is
  629.      because you can modify the HTTP header directly with the hhhheeeeaaaaddddeeeerrrr(((()))) method.
  630.      For example, if you want to send the Refresh: header, do it in the
  631.      _h_e_a_d_e_r() method:
  632.  
  633.          print $q->header(-Refresh=>'10; URL=http://www.capricorn.com');
  634.  
  635.      The ----ssssttttyyyylllleeee tag is used to incorporate cascading stylesheets into your
  636.      code.  See the section on CASCADING STYLESHEETS for more information.
  637.  
  638.      You can place other arbitrary HTML elements to the <HEAD> section with
  639.      the ----hhhheeeeaaaadddd tag.  For example, to place the rarely-used <LINK> element in
  640.      the head section, use this:
  641.  
  642.          print $q->header(-head=>link({-rel=>'next',
  643.                                        -href=>'http://www.capricorn.com/s2.html'}));
  644.  
  645.      To incorporate multiple HTML elements into the <HEAD> section, just pass
  646.      an array reference:
  647.  
  648.          print $q->header(-head=>[ link({-rel=>'next',
  649.                                          -href=>'http://www.capricorn.com/s2.html'}),
  650.                                    link({-rel=>'previous',
  651.                                          -href=>'http://www.capricorn.com/s1.html'})
  652.                                   ]
  653.                           );
  654.  
  655.  
  656.  
  657.                                                                        PPPPaaaaggggeeee 11110000
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  665.  
  666.  
  667.  
  668.      JAVASCRIPTING: The ----ssssccccrrrriiiipppptttt, ----nnnnooooSSSSccccrrrriiiipppptttt, ----oooonnnnLLLLooooaaaadddd and ----oooonnnnUUUUnnnnllllooooaaaadddd parameters
  669.      are used to add Netscape JavaScript calls to your pages.  ----ssssccccrrrriiiipppptttt should
  670.      point to a block of text containing JavaScript function definitions.
  671.      This block will be placed within a <SCRIPT> block inside the HTML (not
  672.      HTTP) header.  The block is placed in the header in order to give your
  673.      page a fighting chance of having all its JavaScript functions in place
  674.      even if the user presses the stop button before the page has loaded
  675.      completely.  CGI.pm attempts to format the script in such a way that
  676.      JavaScript-naive browsers will not choke on the code:  unfortunately
  677.      there are some browsers, such as Chimera for Unix, that get confused by
  678.      it nevertheless.
  679.  
  680.      The ----oooonnnnLLLLooooaaaadddd and ----oooonnnnUUUUnnnnllllooooaaaadddd parameters point to fragments of JavaScript
  681.      code to execute when the page is respectively opened and closed by the
  682.      browser.  Usually these parameters are calls to functions defined in the
  683.      ----ssssccccrrrriiiipppptttt field:
  684.  
  685.            $query = new CGI;
  686.            print $query->header;
  687.            $JSCRIPT=<<END;
  688.            // Ask a silly question
  689.            function riddle_me_this() {
  690.               var r = prompt("What walks on four legs in the morning, " +
  691.                             "two legs in the afternoon, " +
  692.                             "and three legs in the evening?");
  693.               response(r);
  694.            }
  695.            // Get a silly answer
  696.            function response(answer) {
  697.               if (answer == "man")
  698.                  alert("Right you are!");
  699.               else
  700.                  alert("Wrong!  Guess again.");
  701.            }
  702.            END
  703.            print $query->start_html(-title=>'The Riddle of the Sphinx',
  704.                                     -script=>$JSCRIPT);
  705.  
  706.      Use the ----nnnnooooSSSSccccrrrriiiipppptttt parameter to pass some HTML text that will be displayed
  707.      on browsers that do not have JavaScript (or browsers where JavaScript is
  708.      turned off).
  709.  
  710.      Netscape 3.0 recognizes several attributes of the <SCRIPT> tag, including
  711.      LANGUAGE and SRC.  The latter is particularly interesting, as it allows
  712.      you to keep the JavaScript code in a file or CGI script rather than
  713.      cluttering up each page with the source.  To use these attributes pass a
  714.      HASH reference in the ----ssssccccrrrriiiipppptttt parameter containing one or more of
  715.      -language, -src, or -code:
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722.  
  723.                                                                        PPPPaaaaggggeeee 11111111
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  731.  
  732.  
  733.  
  734.          print $q->start_html(-title=>'The Riddle of the Sphinx',
  735.                               -script=>{-language=>'JAVASCRIPT',
  736.                                         -src=>'/javascript/sphinx.js'}
  737.                               );
  738.  
  739.          print $q->(-title=>'The Riddle of the Sphinx',
  740.                     -script=>{-language=>'PERLSCRIPT'},
  741.                               -code=>'print "hello world!\n;"'
  742.                     );
  743.  
  744.      See
  745.  
  746.         http://home.netscape.com/eng/mozilla/2.0/handbook/javascript/
  747.  
  748.      for more information about JavaScript.
  749.  
  750.      The old-style positional parameters are as follows:
  751.  
  752.      PPPPaaaarrrraaaammmmeeeetttteeeerrrrssss::::
  753.  
  754.      1.  The title
  755.  
  756.      2.  The author's e-mail address (will create a <LINK REV="MADE"> tag if
  757.          present
  758.  
  759.      3.  A 'true' flag if you want to include a <BASE> tag in the header.
  760.          This helps resolve relative addresses to absolute ones when the
  761.          document is moved, but makes the document hierarchy non-portable.
  762.          Use with care!
  763.  
  764.      4, 5, 6...
  765.          Any other parameters you want to include in the <BODY> tag.  This is
  766.          a good place to put Netscape extensions, such as colors and wallpaper
  767.          patterns.
  768.  
  769.      EEEENNNNDDDDIIIINNNNGGGG TTTTHHHHEEEE HHHHTTTTMMMMLLLL DDDDOOOOCCCCUUUUMMMMEEEENNNNTTTT::::
  770.  
  771.              print $query->end_html
  772.  
  773.      This ends an HTML document by printing the </BODY></HTML> tags.
  774.  
  775. CCCCRRRREEEEAAAATTTTIIIINNNNGGGG FFFFOOOORRRRMMMMSSSS
  776.      _G_e_n_e_r_a_l _n_o_t_e  The various form-creating methods all return strings to the
  777.      caller, containing the tag or tags that will create the requested form
  778.      element.  You are responsible for actually printing out these strings.
  779.      It's set up this way so that you can place formatting tags around the
  780.      form elements.
  781.  
  782.      _A_n_o_t_h_e_r _n_o_t_e The default values that you specify for the forms are only
  783.      used the ffffiiiirrrrsssstttt time the script is invoked (when there is no query
  784.      string).  On subsequent invocations of the script (when there is a query
  785.      string), the former values are used even if they are blank.
  786.  
  787.  
  788.  
  789.                                                                        PPPPaaaaggggeeee 11112222
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  797.  
  798.  
  799.  
  800.      If you want to change the value of a field from its previous value, you
  801.      have two choices:
  802.  
  803.      (1) call the _p_a_r_a_m() method to set it.
  804.  
  805.      (2) use the -override (alias -force) parameter (a new feature in version
  806.      2.15).  This forces the default value to be used, regardless of the
  807.      previous value:
  808.  
  809.         print $query->textfield(-name=>'field_name',
  810.                                 -default=>'starting value',
  811.                                 -override=>1,
  812.                                 -size=>50,
  813.                                 -maxlength=>80);
  814.  
  815.      _Y_e_t _a_n_o_t_h_e_r _n_o_t_e By default, the text and labels of form elements are
  816.      escaped according to HTML rules.  This means that you can safely use
  817.      "<CLICK ME>" as the label for a button.  However, it also interferes with
  818.      your ability to incorporate special HTML character sequences, such as
  819.      Á, into your fields.  If you wish to turn off automatic escaping,
  820.      call the _a_u_t_o_E_s_c_a_p_e() method with a false value immediately after
  821.      creating the CGI object:
  822.  
  823.         $query = new CGI;
  824.         $query->autoEscape(undef);
  825.  
  826.  
  827.  
  828.      CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAANNNN IIIISSSSIIIINNNNDDDDEEEEXXXX TTTTAAAAGGGG
  829.  
  830.         print $query->isindex(-action=>$action);
  831.  
  832.               -or-
  833.  
  834.         print $query->isindex($action);
  835.  
  836.      Prints out an <ISINDEX> tag.  Not very exciting.  The parameter -action
  837.      specifies the URL of the script to process the query.  The default is to
  838.      process the query with the current script.
  839.  
  840.      SSSSTTTTAAAARRRRTTTTIIIINNNNGGGG AAAANNNNDDDD EEEENNNNDDDDIIIINNNNGGGG AAAA FFFFOOOORRRRMMMM
  841.  
  842.          print $query->startform(-method=>$method,
  843.                                  -action=>$action,
  844.                                  -encoding=>$encoding);
  845.            <... various form stuff ...>
  846.          print $query->endform;
  847.  
  848.              -or-
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.                                                                        PPPPaaaaggggeeee 11113333
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  863.  
  864.  
  865.  
  866.          print $query->startform($method,$action,$encoding);
  867.            <... various form stuff ...>
  868.          print $query->endform;
  869.  
  870.      _s_t_a_r_t_f_o_r_m() will return a <FORM> tag with the optional method, action and
  871.      form encoding that you specify.  The defaults are:
  872.          method: POST
  873.          action: this script
  874.          encoding: application/x-www-form-urlencoded
  875.  
  876.      _e_n_d_f_o_r_m() returns the closing </FORM> tag.
  877.  
  878.      _S_t_a_r_t_f_o_r_m()'s encoding method tells the browser how to package the
  879.      various fields of the form before sending the form to the server.  Two
  880.      values are possible:
  881.  
  882.      aaaapppppppplllliiiiccccaaaattttiiiioooonnnn////xxxx----wwwwwwwwwwww----ffffoooorrrrmmmm----uuuurrrrlllleeeennnnccccooooddddeeeedddd
  883.          This is the older type of encoding used by all browsers prior to
  884.          Netscape 2.0.  It is compatible with many CGI scripts and is suitable
  885.          for short fields containing text data.  For your convenience, CGI.pm
  886.          stores the name of this encoding type in $$$$CCCCGGGGIIII::::::::UUUURRRRLLLL____EEEENNNNCCCCOOOODDDDEEEEDDDD.
  887.  
  888.      mmmmuuuullllttttiiiippppaaaarrrrtttt////ffffoooorrrrmmmm----ddddaaaattttaaaa
  889.          This is the newer type of encoding introduced by Netscape 2.0.  It is
  890.          suitable for forms that contain very large fields or that are
  891.          intended for transferring binary data.  Most importantly, it enables
  892.          the "file upload" feature of Netscape 2.0 forms.  For your
  893.          convenience, CGI.pm stores the name of this encoding type in
  894.          $$$$CCCCGGGGIIII::::::::MMMMUUUULLLLTTTTIIIIPPPPAAAARRRRTTTT
  895.  
  896.          Forms that use this type of encoding are not easily interpreted by
  897.          CGI scripts unless they use CGI.pm or another library designed to
  898.          handle them.
  899.  
  900.      For compatibility, the _s_t_a_r_t_f_o_r_m() method uses the older form of encoding
  901.      by default.  If you want to use the newer form of encoding by default,
  902.      you can call ssssttttaaaarrrrtttt____mmmmuuuullllttttiiiippppaaaarrrrtttt____ffffoooorrrrmmmm(((()))) instead of ssssttttaaaarrrrttttffffoooorrrrmmmm(((()))).
  903.  
  904.      JAVASCRIPTING: The ----nnnnaaaammmmeeee and ----oooonnnnSSSSuuuubbbbmmmmiiiitttt parameters are provided for use
  905.      with JavaScript.  The -name parameter gives the form a name so that it
  906.      can be identified and manipulated by JavaScript functions.  -onSubmit
  907.      should point to a JavaScript function that will be executed just before
  908.      the form is submitted to your server.  You can use this opportunity to
  909.      check the contents of the form for consistency and completeness.  If you
  910.      find something wrong, you can put up an alert box or maybe fix things up
  911.      yourself.  You can abort the submission by returning false from this
  912.      function.
  913.  
  914.      Usually the bulk of JavaScript functions are defined in a <SCRIPT> block
  915.      in the HTML header and -onSubmit points to one of these function call.
  916.      See _s_t_a_r_t__h_t_m_l() for details.
  917.  
  918.  
  919.  
  920.  
  921.                                                                        PPPPaaaaggggeeee 11114444
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  929.  
  930.  
  931.  
  932.      CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA TTTTEEEEXXXXTTTT FFFFIIIIEEEELLLLDDDD
  933.  
  934.          print $query->textfield(-name=>'field_name',
  935.                                  -default=>'starting value',
  936.                                  -size=>50,
  937.                                  -maxlength=>80);
  938.              -or-
  939.  
  940.          print $query->textfield('field_name','starting value',50,80);
  941.  
  942.      _t_e_x_t_f_i_e_l_d() will return a text input field.
  943.  
  944.      PPPPaaaarrrraaaammmmeeeetttteeeerrrrssss
  945.  
  946.      1.  The first parameter is the required name for the field (-name).
  947.  
  948.      2.  The optional second parameter is the default starting value for the
  949.          field contents (-default).
  950.  
  951.      3.  The optional third parameter is the size of the field in
  952.                characters (-size).
  953.  
  954.      4.  The optional fourth parameter is the maximum number of characters the
  955.                field will accept (-maxlength).
  956.  
  957.      As with all these methods, the field will be initialized with its
  958.      previous contents from earlier invocations of the script.  When the form
  959.      is processed, the value of the text field can be retrieved with:
  960.  
  961.             $value = $query->param('foo');
  962.  
  963.      If you want to reset it from its initial value after the script has been
  964.      called once, you can do so like this:
  965.  
  966.             $query->param('foo',"I'm taking over this value!");
  967.  
  968.      NEW AS OF VERSION 2.15: If you don't want the field to take on its
  969.      previous value, you can force its current value by using the -override
  970.      (alias -force) parameter:
  971.  
  972.          print $query->textfield(-name=>'field_name',
  973.                                  -default=>'starting value',
  974.                                  -override=>1,
  975.                                  -size=>50,
  976.                                  -maxlength=>80);
  977.  
  978.      JAVASCRIPTING: You can also provide ----oooonnnnCCCChhhhaaaannnnggggeeee, ----oooonnnnFFFFooooccccuuuussss, ----oooonnnnBBBBlllluuuurrrr and
  979.      ----oooonnnnSSSSeeeelllleeeecccctttt parameters to register JavaScript event handlers.  The onChange
  980.      handler will be called whenever the user changes the contents of the text
  981.      field.  You can do text validation if you like.  onFocus and onBlur are
  982.      called respectively when the insertion point moves into and out of the
  983.      text field.  onSelect is called when the user changes the portion of the
  984.  
  985.  
  986.  
  987.                                                                        PPPPaaaaggggeeee 11115555
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  995.  
  996.  
  997.  
  998.      text that is selected.
  999.  
  1000.      CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA BBBBIIIIGGGG TTTTEEEEXXXXTTTT FFFFIIIIEEEELLLLDDDD
  1001.  
  1002.         print $query->textarea(-name=>'foo',
  1003.                                -default=>'starting value',
  1004.                                -rows=>10,
  1005.                                -columns=>50);
  1006.  
  1007.              -or
  1008.  
  1009.         print $query->textarea('foo','starting value',10,50);
  1010.  
  1011.      _t_e_x_t_a_r_e_a() is just like textfield, but it allows you to specify rows and
  1012.      columns for a multiline text entry box.  You can provide a starting value
  1013.      for the field, which can be long and contain multiple lines.
  1014.  
  1015.      JAVASCRIPTING: The ----oooonnnnCCCChhhhaaaannnnggggeeee, ----oooonnnnFFFFooooccccuuuussss, ----oooonnnnBBBBlllluuuurrrr and ----oooonnnnSSSSeeeelllleeeecccctttt parameters
  1016.      are recognized.  See _t_e_x_t_f_i_e_l_d().
  1017.  
  1018.      CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA PPPPAAAASSSSSSSSWWWWOOOORRRRDDDD FFFFIIIIEEEELLLLDDDD
  1019.  
  1020.         print $query->password_field(-name=>'secret',
  1021.                                      -value=>'starting value',
  1022.                                      -size=>50,
  1023.                                      -maxlength=>80);
  1024.              -or-
  1025.  
  1026.         print $query->password_field('secret','starting value',50,80);
  1027.  
  1028.      _p_a_s_s_w_o_r_d__f_i_e_l_d() is identical to _t_e_x_t_f_i_e_l_d(), except that its contents
  1029.      will be starred out on the web page.
  1030.  
  1031.      JAVASCRIPTING: The ----oooonnnnCCCChhhhaaaannnnggggeeee, ----oooonnnnFFFFooooccccuuuussss, ----oooonnnnBBBBlllluuuurrrr and ----oooonnnnSSSSeeeelllleeeecccctttt parameters
  1032.      are recognized.  See _t_e_x_t_f_i_e_l_d().
  1033.  
  1034.      CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA FFFFIIIILLLLEEEE UUUUPPPPLLLLOOOOAAAADDDD FFFFIIIIEEEELLLLDDDD
  1035.  
  1036.          print $query->filefield(-name=>'uploaded_file',
  1037.                                  -default=>'starting value',
  1038.                                  -size=>50,
  1039.                                  -maxlength=>80);
  1040.              -or-
  1041.  
  1042.          print $query->filefield('uploaded_file','starting value',50,80);
  1043.  
  1044.      _f_i_l_e_f_i_e_l_d() will return a file upload field for Netscape 2.0 browsers.
  1045.      In order to take full advantage of this _y_o_u _m_u_s_t _u_s_e _t_h_e _n_e_w _m_u_l_t_i_p_a_r_t
  1046.      _e_n_c_o_d_i_n_g _s_c_h_e_m_e for the form.  You can do this either by calling
  1047.      ssssttttaaaarrrrttttffffoooorrrrmmmm(((()))) with an encoding type of $$$$CCCCGGGGIIII::::::::MMMMUUUULLLLTTTTIIIIPPPPAAAARRRRTTTT, or by calling the
  1048.      new method ssssttttaaaarrrrtttt____mmmmuuuullllttttiiiippppaaaarrrrtttt____ffffoooorrrrmmmm(((()))) instead of vanilla ssssttttaaaarrrrttttffffoooorrrrmmmm(((()))).
  1049.  
  1050.  
  1051.  
  1052.  
  1053.                                                                        PPPPaaaaggggeeee 11116666
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  1061.  
  1062.  
  1063.  
  1064.      PPPPaaaarrrraaaammmmeeeetttteeeerrrrssss
  1065.  
  1066.      1.  The first parameter is the required name for the field (-name).
  1067.  
  1068.      2.  The optional second parameter is the starting value for the field
  1069.          contents to be used as the default file name (-default).
  1070.  
  1071.          The beta2 version of Netscape 2.0 currently doesn't pay any attention
  1072.          to this field, and so the starting value will always be blank.
  1073.          Worse, the field loses its "sticky" behavior and forgets its previous
  1074.          contents.  The starting value field is called for in the HTML
  1075.          specification, however, and possibly later versions of Netscape will
  1076.          honor it.
  1077.  
  1078.      3.  The optional third parameter is the size of the field in characters
  1079.          (-size).
  1080.  
  1081.      4.  The optional fourth parameter is the maximum number of characters the
  1082.          field will accept (-maxlength).
  1083.  
  1084.      When the form is processed, you can retrieve the entered filename by
  1085.      calling _p_a_r_a_m().
  1086.  
  1087.             $filename = $query->param('uploaded_file');
  1088.  
  1089.      In Netscape Gold, the filename that gets returned is the full local
  1090.      filename on the rrrreeeemmmmooootttteeee uuuusssseeeerrrr''''ssss machine.  If the remote user is on a Unix
  1091.      machine, the filename will follow Unix conventions:
  1092.  
  1093.              /path/to/the/file
  1094.  
  1095.      On an MS-DOS/Windows and OS/2 machines, the filename will follow DOS
  1096.      conventions:
  1097.  
  1098.              C:\PATH\TO\THE\FILE.MSW
  1099.  
  1100.      On a Macintosh machine, the filename will follow Mac conventions:
  1101.  
  1102.              HD 40:Desktop Folder:Sort Through:Reminders
  1103.  
  1104.      The filename returned is also a file handle.  You can read the contents
  1105.      of the file using standard Perl file reading calls:
  1106.  
  1107.              # Read a text file and print it out
  1108.              while (<$filename>) {
  1109.                 print;
  1110.              }
  1111.  
  1112.  
  1113.  
  1114.  
  1115.  
  1116.  
  1117.  
  1118.  
  1119.                                                                        PPPPaaaaggggeeee 11117777
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  1127.  
  1128.  
  1129.  
  1130.              # Copy a binary file to somewhere safe
  1131.              open (OUTFILE,">>/usr/local/web/users/feedback");
  1132.              while ($bytesread=read($filename,$buffer,1024)) {
  1133.                 print OUTFILE $buffer;
  1134.              }
  1135.  
  1136.      When a file is uploaded the browser usually sends along some information
  1137.      along with it in the format of headers.  The information usually includes
  1138.      the MIME content type.  Future browsers may send other information as
  1139.      well (such as modification date and size). To retrieve this information,
  1140.      call _u_p_l_o_a_d_I_n_f_o().  It returns a reference to an associative array
  1141.      containing all the document headers.
  1142.  
  1143.             $filename = $query->param('uploaded_file');
  1144.             $type = $query->uploadInfo($filename)->{'Content-Type'};
  1145.             unless ($type eq 'text/html') {
  1146.                die "HTML FILES ONLY!";
  1147.             }
  1148.  
  1149.      If you are using a machine that recognizes "text" and "binary" data
  1150.      modes, be sure to understand when and how to use them (see the Camel
  1151.      book). Otherwise you may find that binary files are corrupted during file
  1152.      uploads.
  1153.  
  1154.      JAVASCRIPTING: The ----oooonnnnCCCChhhhaaaannnnggggeeee, ----oooonnnnFFFFooooccccuuuussss, ----oooonnnnBBBBlllluuuurrrr and ----oooonnnnSSSSeeeelllleeeecccctttt parameters
  1155.      are recognized.  See _t_e_x_t_f_i_e_l_d() for details.
  1156.  
  1157.      CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA PPPPOOOOPPPPUUUUPPPP MMMMEEEENNNNUUUU
  1158.  
  1159.         print $query->popup_menu('menu_name',
  1160.                                  ['eenie','meenie','minie'],
  1161.                                  'meenie');
  1162.  
  1163.            -or-
  1164.  
  1165.         %labels = ('eenie'=>'your first choice',
  1166.                    'meenie'=>'your second choice',
  1167.                    'minie'=>'your third choice');
  1168.         print $query->popup_menu('menu_name',
  1169.                                  ['eenie','meenie','minie'],
  1170.                                  'meenie',\%labels);
  1171.  
  1172.              -or (named parameter style)-
  1173.  
  1174.         print $query->popup_menu(-name=>'menu_name',
  1175.                                  -values=>['eenie','meenie','minie'],
  1176.                                  -default=>'meenie',
  1177.                                  -labels=>\%labels);
  1178.  
  1179.      _p_o_p_u_p__m_e_n_u() creates a menu.
  1180.  
  1181.  
  1182.  
  1183.  
  1184.  
  1185.                                                                        PPPPaaaaggggeeee 11118888
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  1193.  
  1194.  
  1195.  
  1196.      1.  The required first argument is the menu's name (-name).
  1197.  
  1198.      2.  The required second argument (-values) is an array rrrreeeeffffeeeerrrreeeennnncccceeee
  1199.          containing the list of menu items in the menu.  You can pass the
  1200.          method an anonymous array, as shown in the example, or a reference to
  1201.          a named array, such as "\@foo".
  1202.  
  1203.      3.  The optional third parameter (-default) is the name of the default
  1204.          menu choice.  If not specified, the first item will be the default.
  1205.          The values of the previous choice will be maintained across queries.
  1206.  
  1207.      4.  The optional fourth parameter (-labels) is provided for people who
  1208.          want to use different values for the user-visible label inside the
  1209.          popup menu nd the value returned to your script.  It's a pointer to
  1210.          an associative array relating menu values to user-visible labels.  If
  1211.          you leave this parameter blank, the menu values will be displayed by
  1212.          default.  (You can also leave a label undefined if you want to).
  1213.  
  1214.      When the form is processed, the selected value of the popup menu can be
  1215.      retrieved using:
  1216.  
  1217.            $popup_menu_value = $query->param('menu_name');
  1218.  
  1219.      JAVASCRIPTING: _p_o_p_u_p__m_e_n_u() recognizes the following event handlers:
  1220.      ----oooonnnnCCCChhhhaaaannnnggggeeee, ----oooonnnnFFFFooooccccuuuussss, and ----oooonnnnBBBBlllluuuurrrr.  See the _t_e_x_t_f_i_e_l_d() section for
  1221.      details on when these handlers are called.
  1222.  
  1223.      CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA SSSSCCCCRRRROOOOLLLLLLLLIIIINNNNGGGG LLLLIIIISSSSTTTT
  1224.  
  1225.         print $query->scrolling_list('list_name',
  1226.                                      ['eenie','meenie','minie','moe'],
  1227.                                      ['eenie','moe'],5,'true');
  1228.            -or-
  1229.  
  1230.         print $query->scrolling_list('list_name',
  1231.                                      ['eenie','meenie','minie','moe'],
  1232.                                      ['eenie','moe'],5,'true',
  1233.                                      \%labels);
  1234.  
  1235.              -or-
  1236.  
  1237.         print $query->scrolling_list(-name=>'list_name',
  1238.                                      -values=>['eenie','meenie','minie','moe'],
  1239.                                      -default=>['eenie','moe'],
  1240.                                      -size=>5,
  1241.                                      -multiple=>'true',
  1242.                                      -labels=>\%labels);
  1243.  
  1244.      _s_c_r_o_l_l_i_n_g__l_i_s_t() creates a scrolling list.
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.                                                                        PPPPaaaaggggeeee 11119999
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  1259.  
  1260.  
  1261.  
  1262.      PPPPaaaarrrraaaammmmeeeetttteeeerrrrssss::::
  1263.  
  1264.      1.  The first and second arguments are the list name (-name) and values
  1265.          (-values).  As in the popup menu, the second argument should be an
  1266.          array reference.
  1267.  
  1268.      2.  The optional third argument (-default) can be either a reference to a
  1269.          list containing the values to be selected by default, or can be a
  1270.          single value to select.  If this argument is missing or undefined,
  1271.          then nothing is selected when the list first appears.  In the named
  1272.          parameter version, you can use the synonym "-defaults" for this
  1273.          parameter.
  1274.  
  1275.      3.  The optional fourth argument is the size of the list (-size).
  1276.  
  1277.      4.  The optional fifth argument can be set to true to allow multiple
  1278.          simultaneous selections (-multiple).  Otherwise only one selection
  1279.          will be allowed at a time.
  1280.  
  1281.      5.  The optional sixth argument is a pointer to an associative array
  1282.          containing long user-visible labels for the list items (-labels).  If
  1283.          not provided, the values will be displayed.
  1284.  
  1285.          When this form is processed, all selected list items will be returned
  1286.          as a list under the parameter name 'list_name'.  The values of the
  1287.          selected items can be retrieved with:
  1288.  
  1289.                @selected = $query->param('list_name');
  1290.  
  1291.  
  1292.      JAVASCRIPTING: _s_c_r_o_l_l_i_n_g__l_i_s_t() recognizes the following event handlers:
  1293.      ----oooonnnnCCCChhhhaaaannnnggggeeee, ----oooonnnnFFFFooooccccuuuussss, and ----oooonnnnBBBBlllluuuurrrr.  See _t_e_x_t_f_i_e_l_d() for the description of
  1294.      when these handlers are called.
  1295.  
  1296.      CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA GGGGRRRROOOOUUUUPPPP OOOOFFFF RRRREEEELLLLAAAATTTTEEEEDDDD CCCCHHHHEEEECCCCKKKKBBBBOOOOXXXXEEEESSSS
  1297.  
  1298.         print $query->checkbox_group(-name=>'group_name',
  1299.                                      -values=>['eenie','meenie','minie','moe'],
  1300.                                      -default=>['eenie','moe'],
  1301.                                      -linebreak=>'true',
  1302.                                      -labels=>\%labels);
  1303.  
  1304.         print $query->checkbox_group('group_name',
  1305.                                      ['eenie','meenie','minie','moe'],
  1306.                                      ['eenie','moe'],'true',\%labels);
  1307.  
  1308.         HTML3-COMPATIBLE BROWSERS ONLY:
  1309.  
  1310.         print $query->checkbox_group(-name=>'group_name',
  1311.                                      -values=>['eenie','meenie','minie','moe'],
  1312.                                      -rows=2,-columns=>2);
  1313.  
  1314.  
  1315.  
  1316.  
  1317.                                                                        PPPPaaaaggggeeee 22220000
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  1325.  
  1326.  
  1327.  
  1328.      _c_h_e_c_k_b_o_x__g_r_o_u_p() creates a list of checkboxes that are related by the
  1329.      same name.
  1330.  
  1331.      PPPPaaaarrrraaaammmmeeeetttteeeerrrrssss::::
  1332.  
  1333.      1.  The first and second arguments are the checkbox name and values,
  1334.          respectively (-name and -values).  As in the popup menu, the second
  1335.          argument should be an array reference.  These values are used for the
  1336.          user-readable labels printed next to the checkboxes as well as for
  1337.          the values passed to your script in the query string.
  1338.  
  1339.      2.  The optional third argument (-default) can be either a reference to a
  1340.          list containing the values to be checked by default, or can be a
  1341.          single value to checked.  If this argument is missing or undefined,
  1342.          then nothing is selected when the list first appears.
  1343.  
  1344.      3.  The optional fourth argument (-linebreak) can be set to true to place
  1345.          line breaks between the checkboxes so that they appear as a vertical
  1346.          list.  Otherwise, they will be strung together on a horizontal line.
  1347.  
  1348.      4.  The optional fifth argument is a pointer to an associative array
  1349.          relating the checkbox values to the user-visible labels that will be
  1350.          printed next to them (-labels).  If not provided, the values will be
  1351.          used as the default.
  1352.  
  1353.      5.  HHHHTTTTMMMMLLLL3333----ccccoooommmmppppaaaattttiiiibbbblllleeee bbbbrrrroooowwwwsssseeeerrrrssss (such as Netscape) can take advantage of
  1354.          the optional parameters ----rrrroooowwwwssss, and ----ccccoooolllluuuummmmnnnnssss.  These parameters cause
  1355.          _c_h_e_c_k_b_o_x__g_r_o_u_p() to return an HTML3 compatible table containing the
  1356.          checkbox group formatted with the specified number of rows and
  1357.          columns.  You can provide just the -columns parameter if you wish;
  1358.          checkbox_group will calculate the correct number of rows for you.
  1359.  
  1360.          To include row and column headings in the returned table, you can use
  1361.          the ----rrrroooowwwwhhhheeeeaaaaddddeeeerrrr and ----ccccoooollllhhhheeeeaaaaddddeeeerrrr parameters.  Both of these accept a
  1362.          pointer to an array of headings to use.  The headings are just
  1363.          decorative.  They don't reorganize the interpretation of the
  1364.          checkboxes -- they're still a single named unit.
  1365.  
  1366.      When the form is processed, all checked boxes will be returned as a list
  1367.      under the parameter name 'group_name'.  The values of the "on" checkboxes
  1368.      can be retrieved with:
  1369.  
  1370.            @turned_on = $query->param('group_name');
  1371.  
  1372.      The value returned by _c_h_e_c_k_b_o_x__g_r_o_u_p() is actually an array of button
  1373.      elements.  You can capture them and use them within tables, lists, or in
  1374.      other creative ways:
  1375.  
  1376.          @h = $query->checkbox_group(-name=>'group_name',-values=>\@values);
  1377.          &use_in_creative_way(@h);
  1378.  
  1379.      JAVASCRIPTING: _c_h_e_c_k_b_o_x__g_r_o_u_p() recognizes the ----oooonnnnCCCClllliiiicccckkkk parameter.  This
  1380.  
  1381.  
  1382.  
  1383.                                                                        PPPPaaaaggggeeee 22221111
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  1391.  
  1392.  
  1393.  
  1394.      specifies a JavaScript code fragment or function call to be executed
  1395.      every time the user clicks on any of the buttons in the group.  You can
  1396.      retrieve the identity of the particular button clicked on using the
  1397.      "this" variable.
  1398.  
  1399.      CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA SSSSTTTTAAAANNNNDDDDAAAALLLLOOOONNNNEEEE CCCCHHHHEEEECCCCKKKKBBBBOOOOXXXX
  1400.  
  1401.          print $query->checkbox(-name=>'checkbox_name',
  1402.                                 -checked=>'checked',
  1403.                                 -value=>'ON',
  1404.                                 -label=>'CLICK ME');
  1405.  
  1406.              -or-
  1407.  
  1408.          print $query->checkbox('checkbox_name','checked','ON','CLICK ME');
  1409.  
  1410.      _c_h_e_c_k_b_o_x() is used to create an isolated checkbox that isn't logically
  1411.      related to any others.
  1412.  
  1413.      PPPPaaaarrrraaaammmmeeeetttteeeerrrrssss::::
  1414.  
  1415.      1.  The first parameter is the required name for the checkbox (-name).
  1416.          It will also be used for the user-readable label printed next to the
  1417.          checkbox.
  1418.  
  1419.      2.  The optional second parameter (-checked) specifies that the checkbox
  1420.          is turned on by default.  Synonyms are -selected and -on.
  1421.  
  1422.      3.  The optional third parameter (-value) specifies the value of the
  1423.          checkbox when it is checked.  If not provided, the word "on" is
  1424.          assumed.
  1425.  
  1426.      4.  The optional fourth parameter (-label) is the user-readable label to
  1427.          be attached to the checkbox.  If not provided, the checkbox name is
  1428.          used.
  1429.  
  1430.      The value of the checkbox can be retrieved using:
  1431.  
  1432.          $turned_on = $query->param('checkbox_name');
  1433.  
  1434.      JAVASCRIPTING: _c_h_e_c_k_b_o_x() recognizes the ----oooonnnnCCCClllliiiicccckkkk parameter.  See
  1435.      _c_h_e_c_k_b_o_x__g_r_o_u_p() for further details.
  1436.  
  1437.      CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA RRRRAAAADDDDIIIIOOOO BBBBUUUUTTTTTTTTOOOONNNN GGGGRRRROOOOUUUUPPPP
  1438.  
  1439.         print $query->radio_group(-name=>'group_name',
  1440.                                   -values=>['eenie','meenie','minie'],
  1441.                                   -default=>'meenie',
  1442.                                   -linebreak=>'true',
  1443.                                   -labels=>\%labels);
  1444.  
  1445.              -or-
  1446.  
  1447.  
  1448.  
  1449.                                                                        PPPPaaaaggggeeee 22222222
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  1457.  
  1458.  
  1459.  
  1460.         print $query->radio_group('group_name',['eenie','meenie','minie'],
  1461.                                                'meenie','true',\%labels);
  1462.  
  1463.         HTML3-COMPATIBLE BROWSERS ONLY:
  1464.  
  1465.         print $query->radio_group(-name=>'group_name',
  1466.                                   -values=>['eenie','meenie','minie','moe'],
  1467.                                   -rows=2,-columns=>2);
  1468.  
  1469.      _r_a_d_i_o__g_r_o_u_p() creates a set of logically-related radio buttons (turning
  1470.      one member of the group on turns the others off)
  1471.  
  1472.      PPPPaaaarrrraaaammmmeeeetttteeeerrrrssss::::
  1473.  
  1474.      1.  The first argument is the name of the group and is required (-name).
  1475.  
  1476.      2.  The second argument (-values) is the list of values for the radio
  1477.          buttons.  The values and the labels that appear on the page are
  1478.          identical.  Pass an array _r_e_f_e_r_e_n_c_e in the second argument, either
  1479.          using an anonymous array, as shown, or by referencing a named array
  1480.          as in "\@foo".
  1481.  
  1482.      3.  The optional third parameter (-default) is the name of the default
  1483.          button to turn on. If not specified, the first item will be the
  1484.          default.  You can provide a nonexistent button name, such as "-" to
  1485.          start up with no buttons selected.
  1486.  
  1487.      4.  The optional fourth parameter (-linebreak) can be set to 'true' to
  1488.          put line breaks between the buttons, creating a vertical list.
  1489.  
  1490.      5.  The optional fifth parameter (-labels) is a pointer to an associative
  1491.          array relating the radio button values to user-visible labels to be
  1492.          used in the display.  If not provided, the values themselves are
  1493.          displayed.
  1494.  
  1495.      6.  HHHHTTTTMMMMLLLL3333----ccccoooommmmppppaaaattttiiiibbbblllleeee bbbbrrrroooowwwwsssseeeerrrrssss (such as Netscape) can take advantage of
  1496.          the optional parameters ----rrrroooowwwwssss, and ----ccccoooolllluuuummmmnnnnssss.  These parameters cause
  1497.          _r_a_d_i_o__g_r_o_u_p() to return an HTML3 compatible table containing the
  1498.          radio group formatted with the specified number of rows and columns.
  1499.          You can provide just the -columns parameter if you wish; radio_group
  1500.          will calculate the correct number of rows for you.
  1501.  
  1502.          To include row and column headings in the returned table, you can use
  1503.          the ----rrrroooowwwwhhhheeeeaaaaddddeeeerrrr and ----ccccoooollllhhhheeeeaaaaddddeeeerrrr parameters.  Both of these accept a
  1504.          pointer to an array of headings to use.  The headings are just
  1505.          decorative.  They don't reorganize the interpetation of the radio
  1506.          buttons -- they're still a single named unit.
  1507.  
  1508.      When the form is processed, the selected radio button can be retrieved
  1509.      using:
  1510.  
  1511.  
  1512.  
  1513.  
  1514.  
  1515.                                                                        PPPPaaaaggggeeee 22223333
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  1523.  
  1524.  
  1525.  
  1526.            $which_radio_button = $query->param('group_name');
  1527.  
  1528.      The value returned by _r_a_d_i_o__g_r_o_u_p() is actually an array of button
  1529.      elements.  You can capture them and use them within tables, lists, or in
  1530.      other creative ways:
  1531.  
  1532.          @h = $query->radio_group(-name=>'group_name',-values=>\@values);
  1533.          &use_in_creative_way(@h);
  1534.  
  1535.  
  1536.      CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA SSSSUUUUBBBBMMMMIIIITTTT BBBBUUUUTTTTTTTTOOOONNNN
  1537.  
  1538.         print $query->submit(-name=>'button_name',
  1539.                              -value=>'value');
  1540.  
  1541.              -or-
  1542.  
  1543.         print $query->submit('button_name','value');
  1544.  
  1545.      _s_u_b_m_i_t() will create the query submission button.  Every form should have
  1546.      one of these.
  1547.  
  1548.      PPPPaaaarrrraaaammmmeeeetttteeeerrrrssss::::
  1549.  
  1550.      1.  The first argument (-name) is optional.  You can give the button a
  1551.          name if you have several submission buttons in your form and you want
  1552.          to distinguish between them.  The name will also be used as the
  1553.          user-visible label.  Be aware that a few older browsers don't deal
  1554.          with this correctly and nnnneeeevvvveeeerrrr send back a value from a button.
  1555.  
  1556.      2.  The second argument (-value) is also optional.  This gives the button
  1557.          a value that will be passed to your script in the query string.
  1558.  
  1559.      You can figure out which button was pressed by using different values for
  1560.      each one:
  1561.  
  1562.           $which_one = $query->param('button_name');
  1563.  
  1564.      JAVASCRIPTING: _r_a_d_i_o__g_r_o_u_p() recognizes the ----oooonnnnCCCClllliiiicccckkkk parameter.  See
  1565.      _c_h_e_c_k_b_o_x__g_r_o_u_p() for further details.
  1566.  
  1567.      CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA RRRREEEESSSSEEEETTTT BBBBUUUUTTTTTTTTOOOONNNN
  1568.  
  1569.         print $query->reset
  1570.  
  1571.      _r_e_s_e_t() creates the "reset" button.  Note that it restores the form to
  1572.      its value from the last time the script was called, NOT necessarily to
  1573.      the defaults.
  1574.  
  1575.  
  1576.  
  1577.  
  1578.  
  1579.  
  1580.  
  1581.                                                                        PPPPaaaaggggeeee 22224444
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  1589.  
  1590.  
  1591.  
  1592.      CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA DDDDEEEEFFFFAAAAUUUULLLLTTTT BBBBUUUUTTTTTTTTOOOONNNN
  1593.  
  1594.         print $query->defaults('button_label')
  1595.  
  1596.      _d_e_f_a_u_l_t_s() creates a button that, when invoked, will cause the form to be
  1597.      completely reset to its defaults, wiping out all the changes the user
  1598.      ever made.
  1599.  
  1600.      CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA HHHHIIIIDDDDDDDDEEEENNNN FFFFIIIIEEEELLLLDDDD
  1601.  
  1602.              print $query->hidden(-name=>'hidden_name',
  1603.                                   -default=>['value1','value2'...]);
  1604.  
  1605.                      -or-
  1606.  
  1607.              print $query->hidden('hidden_name','value1','value2'...);
  1608.  
  1609.      _h_i_d_d_e_n() produces a text field that can't be seen by the user.  It is
  1610.      useful for passing state variable information from one invocation of the
  1611.      script to the next.
  1612.  
  1613.      PPPPaaaarrrraaaammmmeeeetttteeeerrrrssss::::
  1614.  
  1615.      1.  The first argument is required and specifies the name of this field
  1616.          (-name).
  1617.  
  1618.      2.  The second argument is also required and specifies its value
  1619.          (-default).  In the named parameter style of calling, you can provide
  1620.          a single value here or a reference to a whole list
  1621.  
  1622.      Fetch the value of a hidden field this way:
  1623.  
  1624.           $hidden_value = $query->param('hidden_name');
  1625.  
  1626.      Note, that just like all the other form elements, the value of a hidden
  1627.      field is "sticky".  If you want to replace a hidden field with some other
  1628.      values after the script has been called once you'll have to do it
  1629.      manually:
  1630.  
  1631.           $query->param('hidden_name','new','values','here');
  1632.  
  1633.  
  1634.      CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA CCCCLLLLIIIICCCCKKKKAAAABBBBLLLLEEEE IIIIMMMMAAAAGGGGEEEE BBBBUUUUTTTTTTTTOOOONNNN
  1635.  
  1636.           print $query->image_button(-name=>'button_name',
  1637.                                      -src=>'/source/URL',
  1638.                                      -align=>'MIDDLE');
  1639.  
  1640.              -or-
  1641.  
  1642.           print $query->image_button('button_name','/source/URL','MIDDLE');
  1643.  
  1644.  
  1645.  
  1646.  
  1647.                                                                        PPPPaaaaggggeeee 22225555
  1648.  
  1649.  
  1650.  
  1651.  
  1652.  
  1653.  
  1654. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  1655.  
  1656.  
  1657.  
  1658.      _i_m_a_g_e__b_u_t_t_o_n() produces a clickable image.  When it's clicked on the
  1659.      position of the click is returned to your script as "button_name.x" and
  1660.      "button_name.y", where "button_name" is the name you've assigned to it.
  1661.  
  1662.      JAVASCRIPTING: _i_m_a_g_e__b_u_t_t_o_n() recognizes the ----oooonnnnCCCClllliiiicccckkkk parameter.  See
  1663.      _c_h_e_c_k_b_o_x__g_r_o_u_p() for further details.
  1664.  
  1665.      PPPPaaaarrrraaaammmmeeeetttteeeerrrrssss::::
  1666.  
  1667.      1.  The first argument (-name) is required and specifies the name of this
  1668.          field.
  1669.  
  1670.      2.  The second argument (-src) is also required and specifies the URL
  1671.  
  1672. BOTTOM or MIDDLE
  1673.      3. The third option (-align, optional) is an alignment type, and may be TOP,
  1674.  
  1675.      Fetch the value of the button this way:
  1676.           $x = $query->_p_a_r_a_m('button_name.x');
  1677.           $y = $query->_p_a_r_a_m('button_name.y');
  1678.  
  1679.      CCCCRRRREEEEAAAATTTTIIIINNNNGGGG AAAA JJJJAAAAVVVVAAAASSSSCCCCRRRRIIIIPPPPTTTT AAAACCCCTTTTIIIIOOOONNNN BBBBUUUUTTTTTTTTOOOONNNN
  1680.  
  1681.           print $query->button(-name=>'button_name',
  1682.                                -value=>'user visible label',
  1683.                                -onClick=>"do_something()");
  1684.  
  1685.              -or-
  1686.  
  1687.           print $query->button('button_name',"do_something()");
  1688.  
  1689.      _b_u_t_t_o_n() produces a button that is compatible with Netscape 2.0's
  1690.      JavaScript.  When it's pressed the fragment of JavaScript code pointed to
  1691.      by the ----oooonnnnCCCClllliiiicccckkkk parameter will be executed.  On non-Netscape browsers
  1692.      this form element will probably not even display.
  1693.  
  1694. NNNNEEEETTTTSSSSCCCCAAAAPPPPEEEE CCCCOOOOOOOOKKKKIIIIEEEESSSS
  1695.      Netscape browsers versions 1.1 and higher support a so-called "cookie"
  1696.      designed to help maintain state within a browser session.  CGI.pm has
  1697.      several methods that support cookies.
  1698.  
  1699.      A cookie is a name=value pair much like the named parameters in a CGI
  1700.      query string.  CGI scripts create one or more cookies and send them to
  1701.      the browser in the HTTP header.  The browser maintains a list of cookies
  1702.      that belong to a particular Web server, and returns them to the CGI
  1703.      script during subsequent interactions.
  1704.  
  1705.      In addition to the required name=value pair, each cookie has several
  1706.      optional attributes:
  1707.  
  1708.  
  1709.  
  1710.  
  1711.  
  1712.  
  1713.                                                                        PPPPaaaaggggeeee 22226666
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  1721.  
  1722.  
  1723.  
  1724.      1. an expiration time
  1725.          This is a time/date string (in a special GMT format) that indicates
  1726.          when a cookie expires.  The cookie will be saved and returned to your
  1727.          script until this expiration date is reached if the user exits
  1728.          Netscape and restarts it.  If an expiration date isn't specified, the
  1729.          cookie will remain active until the user quits Netscape.
  1730.  
  1731.      2. a domain
  1732.          This is a partial or complete domain name for which the cookie is
  1733.          valid.  The browser will return the cookie to any host that matches
  1734.          the partial domain name.  For example, if you specify a domain name
  1735.          of ".capricorn.com", then Netscape will return the cookie to Web
  1736.          servers running on any of the machines "www.capricorn.com",
  1737.          "www2.capricorn.com", "feckless.capricorn.com", etc.  Domain names
  1738.          must contain at least two periods to prevent attempts to match on top
  1739.          level domains like ".edu".  If no domain is specified, then the
  1740.          browser will only return the cookie to servers on the host the cookie
  1741.          originated from.
  1742.  
  1743.      3. a path
  1744.          If you provide a cookie path attribute, the browser will check it
  1745.          against your script's URL before returning the cookie.  For example,
  1746.          if you specify the path "/cgi-bin", then the cookie will be returned
  1747.          to each of the scripts "/cgi-bin/tally.pl", "/cgi-bin/order.pl", and
  1748.          "/cgi-bin/customer_service/complain.pl", but not to the script
  1749.          "/cgi-private/site_admin.pl".  By default, path is set to "/", which
  1750.          causes the cookie to be sent to any CGI script on your site.
  1751.  
  1752.      4. a "secure" flag
  1753.          If the "secure" attribute is set, the cookie will only be sent to
  1754.          your script if the CGI request is occurring on a secure channel, such
  1755.          as SSL.
  1756.  
  1757.      The interface to Netscape cookies is the ccccooooooookkkkiiiieeee(((()))) method:
  1758.  
  1759.          $cookie = $query->cookie(-name=>'sessionID',
  1760.                                   -value=>'xyzzy',
  1761.                                   -expires=>'+1h',
  1762.                                   -path=>'/cgi-bin/database',
  1763.                                   -domain=>'.capricorn.org',
  1764.                                   -secure=>1);
  1765.          print $query->header(-cookie=>$cookie);
  1766.  
  1767.      ccccooooooookkkkiiiieeee(((()))) creates a new cookie.  Its parameters include:
  1768.  
  1769.      ----nnnnaaaammmmeeee
  1770.          The name of the cookie (required).  This can be any string at all.
  1771.          Although Netscape limits its cookie names to non-whitespace
  1772.          alphanumeric characters, CGI.pm removes this restriction by escaping
  1773.          and unescaping cookies behind the scenes.
  1774.  
  1775.  
  1776.  
  1777.  
  1778.  
  1779.                                                                        PPPPaaaaggggeeee 22227777
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  1787.  
  1788.  
  1789.  
  1790.      ----vvvvaaaalllluuuueeee
  1791.          The value of the cookie.  This can be any scalar value, array
  1792.          reference, or even associative array reference.  For example, you can
  1793.          store an entire associative array into a cookie this way:
  1794.  
  1795.                  $cookie=$query->cookie(-name=>'family information',
  1796.                                         -value=>\%childrens_ages);
  1797.  
  1798.  
  1799.      ----ppppaaaatttthhhh
  1800.          The optional partial path for which this cookie will be valid, as
  1801.          described above.
  1802.  
  1803.      ----ddddoooommmmaaaaiiiinnnn
  1804.          The optional partial domain for which this cookie will be valid, as
  1805.          described above.
  1806.  
  1807.      ----eeeexxxxppppiiiirrrreeeessss
  1808.          The optional expiration date for this cookie.  The format is as
  1809.          described in the section on the hhhheeeeaaaaddddeeeerrrr(((()))) method:
  1810.  
  1811.                  "+1h"  one hour from now
  1812.  
  1813.  
  1814.      ----sssseeeeccccuuuurrrreeee
  1815.          If set to true, this cookie will only be used within a secure SSL
  1816.          session.
  1817.  
  1818.      The cookie created by _c_o_o_k_i_e() must be incorporated into the HTTP header
  1819.      within the string returned by the _h_e_a_d_e_r() method:
  1820.  
  1821.              print $query->header(-cookie=>$my_cookie);
  1822.  
  1823.      To create multiple cookies, give _h_e_a_d_e_r() an array reference:
  1824.  
  1825.              $cookie1 = $query->cookie(-name=>'riddle_name',
  1826.                                        -value=>"The Sphynx's Question");
  1827.              $cookie2 = $query->cookie(-name=>'answers',
  1828.                                        -value=>\%answers);
  1829.              print $query->header(-cookie=>[$cookie1,$cookie2]);
  1830.  
  1831.      To retrieve a cookie, request it by name by calling _c_o_o_k_i_e() method
  1832.      without the ----vvvvaaaalllluuuueeee parameter:
  1833.  
  1834.              use CGI;
  1835.              $query = new CGI;
  1836.              %answers = $query->cookie(-name=>'answers');
  1837.              # $query->cookie('answers') will work too!
  1838.  
  1839.      The cookie and CGI namespaces are separate.  If you have a parameter
  1840.      named 'answers' and a cookie named 'answers', the values retrieved by
  1841.      _p_a_r_a_m() and _c_o_o_k_i_e() are independent of each other.  However, it's simple
  1842.  
  1843.  
  1844.  
  1845.                                                                        PPPPaaaaggggeeee 22228888
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  1853.  
  1854.  
  1855.  
  1856.      to turn a CGI parameter into a cookie, and vice-versa:
  1857.  
  1858.         # turn a CGI parameter into a cookie
  1859.         $c=$q->cookie(-name=>'answers',-value=>[$q->param('answers')]);
  1860.         # vice-versa
  1861.         $q->param(-name=>'answers',-value=>[$q->cookie('answers')]);
  1862.  
  1863.      See the ccccooooooookkkkiiiieeee....ccccggggiiii example script for some ideas on how to use cookies
  1864.      effectively.
  1865.  
  1866.      NNNNOOOOTTTTEEEE:::: There appear to be some (undocumented) restrictions on Netscape
  1867.      cookies.  In Netscape 2.01, at least, I haven't been able to set more
  1868.      than three cookies at a time.  There may also be limits on the length of
  1869.      cookies.  If you need to store a lot of information, it's probably better
  1870.      to create a unique session ID, store it in a cookie, and use the session
  1871.      ID to locate an external file/database saved on the server's side of the
  1872.      connection.
  1873.  
  1874. WWWWOOOORRRRKKKKIIIINNNNGGGG WWWWIIIITTTTHHHH NNNNEEEETTTTSSSSCCCCAAAAPPPPEEEE FFFFRRRRAAAAMMMMEEEESSSS
  1875.      It's possible for CGI.pm scripts to write into several browser panels and
  1876.      windows using Netscape's frame mechanism. There are three techniques for
  1877.      defining new frames programmatically:
  1878.  
  1879.      1. Create a <Frameset> document
  1880.          After writing out the HTTP header, instead of creating a standard
  1881.          HTML document using the _s_t_a_r_t__h_t_m_l() call, create a <FRAMESET>
  1882.          document that defines the frames on the page.  Specify your _s_c_r_i_p_t(s)
  1883.          (with appropriate parameters) as the SRC for each of the frames.
  1884.  
  1885.          There is no specific support for creating <FRAMESET> sections in
  1886.          CGI.pm, but the HTML is very simple to write.  See the frame
  1887.          documentation in Netscape's home pages for details
  1888.  
  1889.            http://home.netscape.com/assist/net_sites/frames.html
  1890.  
  1891.  
  1892.      2. Specify the destination for the document in the HTTP header
  1893.          You may provide a ----ttttaaaarrrrggggeeeetttt parameter to the _h_e_a_d_e_r() method:
  1894.  
  1895.              print $q->_h_e_a_d_e_r(-target=>'ResultsWindow');
  1896.  
  1897.          This will tell Netscape to load the output of your script into the
  1898.          frame named "ResultsWindow".  If a frame of that name doesn't already
  1899.          exist, Netscape will pop up a new window and load your script's
  1900.          document into that.  There are a number of magic names that you can
  1901.          use for targets.  See the frame documents on Netscape's home pages
  1902.          for details.
  1903.  
  1904.      3. Specify the destination for the document in the <FORM> tag
  1905.          You can specify the frame to load in the FORM tag itself.  With
  1906.          CGI.pm it looks like this:
  1907.  
  1908.  
  1909.  
  1910.  
  1911.                                                                        PPPPaaaaggggeeee 22229999
  1912.  
  1913.  
  1914.  
  1915.  
  1916.  
  1917.  
  1918. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  1919.  
  1920.  
  1921.  
  1922.              print $q->startform(-target=>'ResultsWindow');
  1923.  
  1924.          When your script is reinvoked by the form, its output will be loaded
  1925.          into the frame named "ResultsWindow".  If one doesn't already exist a
  1926.          new window will be created.
  1927.  
  1928.      The script "frameset.cgi" in the examples directory shows one way to
  1929.      create pages in which the fill-out form and the response live in side-
  1930.      by-side frames.
  1931.  
  1932. LLLLIIIIMMMMIIIITTTTEEEEDDDD SSSSUUUUPPPPPPPPOOOORRRRTTTT FFFFOOOORRRR CCCCAAAASSSSCCCCAAAADDDDIIIINNNNGGGG SSSSTTTTYYYYLLLLEEEE SSSSHHHHEEEEEEEETTTTSSSS
  1933.      CGI.pm has limited support for HTML3's cascading style sheets (css).  To
  1934.      incorporate a stylesheet into your document, pass the _s_t_a_r_t__h_t_m_l() method
  1935.      a ----ssssttttyyyylllleeee parameter.  The value of this parameter may be a scalar, in
  1936.      which case it is incorporated directly into a <STYLE> section, or it may
  1937.      be a hash reference.  In the latter case you should provide the hash with
  1938.      one or more of ----ssssrrrrcccc or ----ccccooooddddeeee.  ----ssssrrrrcccc points to a URL where an externally-
  1939.      defined stylesheet can be found.  ----ccccooooddddeeee points to a scalar value to be
  1940.      incorporated into a <STYLE> section.  Style definitions in ----ccccooooddddeeee override
  1941.      similarly-named ones in ----ssssrrrrcccc, hence the name "cascading."
  1942.  
  1943.      To refer to a style within the body of your document, add the ----ccccllllaaaassssssss
  1944.      parameter to any HTML element:
  1945.  
  1946.          print h1({-class=>'Fancy'},'Welcome to the Party');
  1947.  
  1948.      Or define styles on the fly with the ----ssssttttyyyylllleeee parameter:
  1949.  
  1950.          print h1({-style=>'Color: red;'},'Welcome to Hell');
  1951.  
  1952.      You may also use the new ssssppppaaaannnn(((()))) element to apply a style to a section of
  1953.      text:
  1954.  
  1955.          print span({-style=>'Color: red;'},
  1956.                     h1('Welcome to Hell'),
  1957.                     "Where did that handbasket get to?"
  1958.                     );
  1959.  
  1960.      Note that you must import the ":html3" definitions to have the ssssppppaaaannnn(((())))
  1961.      method available.  Here's a quick and dirty example of using CSS's.  See
  1962.      the CSS specification at http://www.w3.org/pub/WWW/TR/Wd-css-1.html for
  1963.      more information.
  1964.  
  1965.          use CGI qw/:standard :html3/;
  1966.  
  1967.  
  1968.  
  1969.  
  1970.  
  1971.  
  1972.  
  1973.  
  1974.  
  1975.  
  1976.  
  1977.                                                                        PPPPaaaaggggeeee 33330000
  1978.  
  1979.  
  1980.  
  1981.  
  1982.  
  1983.  
  1984. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  1985.  
  1986.  
  1987.  
  1988.          #here's a stylesheet incorporated directly into the page
  1989.          $newStyle=<<END;
  1990.          <!--
  1991.          P.Tip {
  1992.              margin-right: 50pt;
  1993.              margin-left: 50pt;
  1994.              color: red;
  1995.          }
  1996.          P.Alert {
  1997.              font-size: 30pt;
  1998.              font-family: sans-serif;
  1999.            color: red;
  2000.          }
  2001.          -->
  2002.          END
  2003.          print header();
  2004.          print start_html( -title=>'CGI with Style',
  2005.                            -style=>{-src=>'http://www.capricorn.com/style/st1.css',
  2006.                                     -code=>$newStyle}
  2007.                           );
  2008.          print h1('CGI with Style'),
  2009.                p({-class=>'Tip'},
  2010.                  "Better read the cascading style sheet spec before playing with this!"),
  2011.                span({-style=>'color: magenta'},
  2012.                     "Look Mom, no hands!",
  2013.                     p(),
  2014.                     "Whooo wee!"
  2015.                     );
  2016.          print end_html;
  2017.  
  2018.  
  2019. DDDDEEEEBBBBUUUUGGGGGGGGIIIINNNNGGGG
  2020.      If you are running the script from the command line or in the perl
  2021.      debugger, you can pass the script a list of keywords or parameter=value
  2022.      pairs on the command line or from standard input (you don't have to worry
  2023.      about tricking your script into reading from environment variables).  You
  2024.      can pass keywords like this:
  2025.  
  2026.          your_script.pl keyword1 keyword2 keyword3
  2027.  
  2028.      or this:
  2029.  
  2030.         your_script.pl keyword1+keyword2+keyword3
  2031.  
  2032.      or this:
  2033.  
  2034.          your_script.pl name1=value1 name2=value2
  2035.  
  2036.      or this:
  2037.  
  2038.  
  2039.  
  2040.  
  2041.  
  2042.  
  2043.                                                                        PPPPaaaaggggeeee 33331111
  2044.  
  2045.  
  2046.  
  2047.  
  2048.  
  2049.  
  2050. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  2051.  
  2052.  
  2053.  
  2054.          your_script.pl name1=value1&name2=value2
  2055.  
  2056.      or even as newline-delimited parameters on standard input.
  2057.  
  2058.      When debugging, you can use quotes and backslashes to escape characters
  2059.      in the familiar shell manner, letting you place spaces and other funny
  2060.      characters in your parameter=value pairs:
  2061.  
  2062.         your_script.pl "name1='I am a long value'" "name2=two\ words"
  2063.  
  2064.  
  2065.      DDDDUUUUMMMMPPPPIIIINNNNGGGG OOOOUUUUTTTT AAAALLLLLLLL TTTTHHHHEEEE NNNNAAAAMMMMEEEE////VVVVAAAALLLLUUUUEEEE PPPPAAAAIIIIRRRRSSSS
  2066.  
  2067.      The _d_u_m_p() method produces a string consisting of all the query's
  2068.      name/value pairs formatted nicely as a nested list.  This is useful for
  2069.      debugging purposes:
  2070.  
  2071.          print $query->dump
  2072.  
  2073.  
  2074.      Produces something that looks like:
  2075.  
  2076.          <UL>
  2077.          <LI>name1
  2078.              <UL>
  2079.              <LI>value1
  2080.              <LI>value2
  2081.              </UL>
  2082.          <LI>name2
  2083.              <UL>
  2084.              <LI>value1
  2085.              </UL>
  2086.          </UL>
  2087.  
  2088.      You can pass a value of 'true' to _d_u_m_p() in order to get it to print the
  2089.      results out as plain text, suitable for incorporating into a <PRE>
  2090.      section.
  2091.  
  2092.      As a shortcut, as of version 1.56 you can interpolate the entire CGI
  2093.      object into a string and it will be replaced with the a nice HTML dump
  2094.      shown above:
  2095.  
  2096.          $query=new CGI;
  2097.          print "<H2>Current Values</H2> $query\n";
  2098.  
  2099.  
  2100. FFFFEEEETTTTCCCCHHHHIIIINNNNGGGG EEEENNNNVVVVIIIIRRRROOOONNNNMMMMEEEENNNNTTTT VVVVAAAARRRRIIIIAAAABBBBLLLLEEEESSSS
  2101.      Some of the more useful environment variables can be fetched through this
  2102.      interface.  The methods are as follows:
  2103.  
  2104.  
  2105.  
  2106.  
  2107.  
  2108.  
  2109.                                                                        PPPPaaaaggggeeee 33332222
  2110.  
  2111.  
  2112.  
  2113.  
  2114.  
  2115.  
  2116. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  2117.  
  2118.  
  2119.  
  2120.      aaaacccccccceeeepppptttt(((())))
  2121.          Return a list of MIME types that the remote browser accepts. If you
  2122.          give this method a single argument corresponding to a MIME type, as
  2123.          in $query->_a_c_c_e_p_t('text/html'), it will return a floating point value
  2124.          corresponding to the browser's preference for this type from 0.0
  2125.          (don't want) to 1.0.  Glob types (e.g. text/*) in the browser's
  2126.          accept list are handled correctly.
  2127.  
  2128.      rrrraaaawwww____ccccooooooookkkkiiiieeee(((())))
  2129.          Returns the HTTP_COOKIE variable, an HTTP extension implemented by
  2130.          Netscape browsers version 1.1 and higher.  Cookies have a special
  2131.          format, and this method call just returns the raw form (?cookie
  2132.          dough).  See _c_o_o_k_i_e() for ways of setting and retrieving cooked
  2133.          cookies.
  2134.  
  2135.      uuuusssseeeerrrr____aaaaggggeeeennnntttt(((())))
  2136.          Returns the HTTP_USER_AGENT variable.  If you give this method a
  2137.          single argument, it will attempt to pattern match on it, allowing you
  2138.          to do something like $query->_u_s_e_r__a_g_e_n_t(netscape);
  2139.  
  2140.      ppppaaaatttthhhh____iiiinnnnffffoooo(((())))
  2141.          Returns additional path information from the script URL.  E.G.
  2142.          fetching /cgi-bin/your_script/additional/stuff will result in
  2143.          $query->_p_a_t_h__i_n_f_o() returning "additional/stuff".
  2144.  
  2145.          NOTE: The Microsoft Internet Information Server is broken with
  2146.          respect to additional path information.  If you use the Perl DLL
  2147.          library, the IIS server will attempt to execute the additional path
  2148.          information as a Perl script.  If you use the ordinary file
  2149.          associations mapping, the path information will be present in the
  2150.          environment, but incorrect.  The best thing to do is to avoid using
  2151.          additional path information in CGI scripts destined for use with IIS.
  2152.  
  2153.      ppppaaaatttthhhh____ttttrrrraaaannnnssssllllaaaatttteeeedddd(((())))
  2154.          As per _p_a_t_h__i_n_f_o() but returns the additional path information
  2155.          translated into a physical path, e.g.
  2156.          "/usr/local/etc/httpd/htdocs/additional/stuff".
  2157.  
  2158.          The Microsoft IIS is broken with respect to the translated path as
  2159.          well.
  2160.  
  2161.      rrrreeeemmmmooootttteeee____hhhhoooosssstttt(((())))
  2162.          Returns either the remote host name or IP address.  if the former is
  2163.          unavailable.
  2164.  
  2165. scripts.
  2166.      ssssccccrrrriiiipppptttt____nnnnaaaammmmeeee(((()))) Return the script name as a partial URL, for self-refering
  2167.  
  2168.      rrrreeeeffffeeeerrrreeeerrrr(((())))
  2169.          Return the URL of the page the browser was viewing prior to fetching
  2170.          your script.  Not available for all browsers.
  2171.  
  2172.  
  2173.  
  2174.  
  2175.                                                                        PPPPaaaaggggeeee 33333333
  2176.  
  2177.  
  2178.  
  2179.  
  2180.  
  2181.  
  2182. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  2183.  
  2184.  
  2185.  
  2186.      aaaauuuutttthhhh____ttttyyyyppppeeee (((())))
  2187.          Return the authorization/verification method in use for this script,
  2188.          if any.
  2189.  
  2190.      sssseeeerrrrvvvveeeerrrr____nnnnaaaammmmeeee (((())))
  2191.          Returns the name of the server, usually the machine's host name.
  2192.  
  2193.      vvvviiiirrrrttttuuuuaaaallll____hhhhoooosssstttt (((())))
  2194.          When using virtual hosts, returns the name of the host that the
  2195.          browser attempted to contact
  2196.  
  2197.      sssseeeerrrrvvvveeeerrrr____ssssooooffffttttwwwwaaaarrrreeee (((())))
  2198.          Returns the server software and version number.
  2199.  
  2200.      rrrreeeemmmmooootttteeee____uuuusssseeeerrrr (((())))
  2201.          Return the authorization/verification name used for user
  2202.          verification, if this script is protected.
  2203.  
  2204.      uuuusssseeeerrrr____nnnnaaaammmmeeee (((())))
  2205.          Attempt to obtain the remote user's name, using a variety of
  2206.          different techniques.  This only works with older browsers such as
  2207.          Mosaic.  Netscape does not reliably report the user name!
  2208.  
  2209.      rrrreeeeqqqquuuueeeesssstttt____mmmmeeeetttthhhhoooodddd(((())))
  2210.          Returns the method used to access your script, usually one of 'POST',
  2211.          'GET' or 'HEAD'.
  2212.  
  2213. CCCCRRRREEEEAAAATTTTIIIINNNNGGGG HHHHTTTTMMMMLLLL EEEELLLLEEEEMMMMEEEENNNNTTTTSSSS
  2214.      In addition to its shortcuts for creating form elements, CGI.pm defines
  2215.      general HTML shortcut methods as well.  HTML shortcuts are named after a
  2216.      single HTML element and return a fragment of HTML text that you can then
  2217.      print or manipulate as you like.
  2218.  
  2219.      This example shows how to use the HTML methods:
  2220.  
  2221.              $q = new CGI;
  2222.              print $q->blockquote(
  2223.                                   "Many years ago on the island of",
  2224.                                   $q->a({href=>"http://crete.org/"},"Crete"),
  2225.                                   "there lived a minotaur named",
  2226.                                   $q->strong("Fred."),
  2227.                                  ),
  2228.                     $q->hr;
  2229.  
  2230.      This results in the following HTML code (extra newlines have been added
  2231.      for readability):
  2232.  
  2233.  
  2234.  
  2235.  
  2236.  
  2237.  
  2238.  
  2239.  
  2240.  
  2241.                                                                        PPPPaaaaggggeeee 33334444
  2242.  
  2243.  
  2244.  
  2245.  
  2246.  
  2247.  
  2248. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  2249.  
  2250.  
  2251.  
  2252.              <blockquote>
  2253.              Many years ago on the island of
  2254.              <a HREF="http://crete.org/">Crete</a> there lived
  2255.              a minotaur named <strong>Fred.</strong>
  2256.              </blockquote>
  2257.              <hr>
  2258.  
  2259.      If you find the syntax for calling the HTML shortcuts awkward, you can
  2260.      import them into your namespace and dispense with the object syntax
  2261.      completely (see the next section for more details):
  2262.  
  2263.              use CGI shortcuts;      # IMPORT HTML SHORTCUTS
  2264.              print blockquote(
  2265.                           "Many years ago on the island of",
  2266.                           a({href=>"http://crete.org/"},"Crete"),
  2267.                           "there lived a minotaur named",
  2268.                           strong("Fred."),
  2269.                           ),
  2270.                     hr;
  2271.  
  2272.  
  2273.      PPPPRRRROOOOVVVVIIIIDDDDIIIINNNNGGGG AAAARRRRGGGGUUUUMMMMEEEENNNNTTTTSSSS TTTTOOOO HHHHTTTTMMMMLLLL SSSSHHHHOOOORRRRTTTTCCCCUUUUTTTTSSSS
  2274.  
  2275.      The HTML methods will accept zero, one or multiple arguments.  If you
  2276.      provide no arguments, you get a single tag:
  2277.  
  2278.              print hr;
  2279.              #  gives "<hr>"
  2280.  
  2281.      If you provide one or more string arguments, they are concatenated
  2282.      together with spaces and placed between opening and closing tags:
  2283.  
  2284.              print h1("Chapter","1");
  2285.              # gives "<h1>Chapter 1</h1>"
  2286.  
  2287.      If the first argument is an associative array reference, then the keys
  2288.      and values of the associative array become the HTML tag's attributes:
  2289.  
  2290.              print a({href=>'fred.html',target=>'_new'},
  2291.                      "Open a new frame");
  2292.              # gives <a href="fred.html",target="_new">Open a new frame</a>
  2293.  
  2294.      You are free to use CGI.pm-style dashes in front of the attribute names
  2295.      if you prefer:
  2296.  
  2297.              print img {-src=>'fred.gif',-align=>'LEFT'};
  2298.              # gives <img ALIGN="LEFT" SRC="fred.gif">
  2299.  
  2300.  
  2301.  
  2302.  
  2303.  
  2304.  
  2305.  
  2306.  
  2307.                                                                        PPPPaaaaggggeeee 33335555
  2308.  
  2309.  
  2310.  
  2311.  
  2312.  
  2313.  
  2314. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  2315.  
  2316.  
  2317.  
  2318.      GGGGeeeennnneeeerrrraaaattttiiiinnnngggg nnnneeeewwww HHHHTTTTMMMMLLLL ttttaaaaggggssss
  2319.  
  2320.      Since no mere mortal can keep up with Netscape and Microsoft as they
  2321.      battle it out for control of HTML, the code that generates HTML tags is
  2322.      general and extensible.  You can create new HTML tags freely just by
  2323.      referring to them on the import line:
  2324.  
  2325.              use CGI shortcuts,winkin,blinkin,nod;
  2326.  
  2327.      Now, in addition to the standard CGI shortcuts, you've created HTML tags
  2328.      named "winkin", "blinkin" and "nod".  You can use them like this:
  2329.  
  2330.              print blinkin {color=>'blue',rate=>'fast'},"Yahoo!";
  2331.              # <blinkin COLOR="blue" RATE="fast">Yahoo!</blinkin>
  2332.  
  2333.  
  2334. IIIIMMMMPPPPOOOORRRRTTTTIIIINNNNGGGG CCCCGGGGIIII MMMMEEEETTTTHHHHOOOODDDD CCCCAAAALLLLLLLLSSSS IIIINNNNTTTTOOOO YYYYOOOOUUUURRRR NNNNAAAAMMMMEEEE SSSSPPPPAAAACCCCEEEE
  2335.      As a convenience, you can import most of the CGI method calls directly
  2336.      into your name space.  The syntax for doing this is:
  2337.  
  2338.              use CGI <list of methods>;
  2339.  
  2340.      The listed methods will be imported into the current package; you can
  2341.      call them directly without creating a CGI object first.  This example
  2342.      shows how to import the ppppaaaarrrraaaammmm(((()))) and hhhheeeeaaaaddddeeeerrrr(((()))) methods, and then use them
  2343.      directly:
  2344.  
  2345.              use CGI param,header;
  2346.              print header('text/plain');
  2347.              $zipcode = param('zipcode');
  2348.  
  2349.      You can import groups of methods by referring to a number of special
  2350.      names:
  2351.  
  2352.      ccccggggiiii Import all CGI-handling methods, such as ppppaaaarrrraaaammmm(((()))), ppppaaaatttthhhh____iiiinnnnffffoooo(((()))) and the
  2353.          like.
  2354.  
  2355.      ffffoooorrrrmmmm
  2356.          Import all fill-out form generating methods, such as tttteeeexxxxttttffffiiiieeeelllldddd(((()))).
  2357.  
  2358.      hhhhttttmmmmllll2222
  2359.          Import all methods that generate HTML 2.0 standard elements.
  2360.  
  2361.      hhhhttttmmmmllll3333
  2362.          Import all methods that generate HTML 3.0 proposed elements (such as
  2363.          <table>, <super> and <sub>).
  2364.  
  2365.      nnnneeeettttssssccccaaaappppeeee
  2366.          Import all methods that generate Netscape-specific HTML extensions.
  2367.  
  2368.  
  2369.  
  2370.  
  2371.  
  2372.  
  2373.                                                                        PPPPaaaaggggeeee 33336666
  2374.  
  2375.  
  2376.  
  2377.  
  2378.  
  2379.  
  2380. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  2381.  
  2382.  
  2383.  
  2384.      sssshhhhoooorrrrttttccccuuuuttttssss
  2385.          Import all HTML-generating shortcuts (i.e. 'html2' + 'html3' +
  2386.          'netscape')...
  2387.  
  2388.      ssssttttaaaannnnddddaaaarrrrdddd
  2389.          Import "standard" features, 'html2', 'form' and 'cgi'.
  2390.  
  2391.      aaaallllllll Import all the available methods.  For the full list, see the CGI.pm
  2392.          code, where the variable %TAGS is defined.
  2393.  
  2394.      Note that in the interests of execution speed CGI.pm does nnnnooootttt use the
  2395.      standard the _E_x_p_o_r_t_e_r manpage syntax for specifying load symbols.  This
  2396.      may change in the future.
  2397.  
  2398.      If you import any of the state-maintaining CGI or form-generating
  2399.      methods, a default CGI object will be created and initialized
  2400.      automatically the first time you use any of the methods that require one
  2401.      to be present.  This includes ppppaaaarrrraaaammmm(((()))), tttteeeexxxxttttffffiiiieeeelllldddd(((()))), ssssuuuubbbbmmmmiiiitttt(((()))) and the
  2402.      like.  (If you need direct access to the CGI object, you can find it in
  2403.      the global variable $$$$CCCCGGGGIIII::::::::QQQQ).  By importing CGI.pm methods, you can
  2404.      create visually elegant scripts:
  2405.  
  2406.         use CGI standard,html2;
  2407.         print
  2408.             header,
  2409.             start_html('Simple Script'),
  2410.             h1('Simple Script'),
  2411.             start_form,
  2412.             "What's your name? ",textfield('name'),p,
  2413.             "What's the combination?",
  2414.             checkbox_group(-name=>'words',
  2415.                            -values=>['eenie','meenie','minie','moe'],
  2416.                            -defaults=>['eenie','moe']),p,
  2417.             "What's your favorite color?",
  2418.             popup_menu(-name=>'color',
  2419.                        -values=>['red','green','blue','chartreuse']),p,
  2420.             submit,
  2421.             end_form,
  2422.             hr,"\n";
  2423.  
  2424.          if (param) {
  2425.             print
  2426.                 "Your name is ",em(param('name')),p,
  2427.                 "The keywords are: ",em(join(", ",param('words'))),p,
  2428.                 "Your favorite color is ",em(param('color')),".\n";
  2429.          }
  2430.          print end_html;
  2431.  
  2432.  
  2433.  
  2434.  
  2435.  
  2436.  
  2437.  
  2438.  
  2439.                                                                        PPPPaaaaggggeeee 33337777
  2440.  
  2441.  
  2442.  
  2443.  
  2444.  
  2445.  
  2446. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  2447.  
  2448.  
  2449.  
  2450. USING NPH SCRIPTS
  2451.      NPH, or "no-parsed-header", scripts bypass the server completely by
  2452.      sending the complete HTTP header directly to the browser.  This has
  2453.      slight performance benefits, but is of most use for taking advantage of
  2454.      HTTP extensions that are not directly supported by your server, such as
  2455.      server push and PICS headers.
  2456.  
  2457.      Servers use a variety of conventions for designating CGI scripts as NPH.
  2458.      Many Unix servers look at the beginning of the script's name for the
  2459.      prefix "nph-".  The Macintosh WebSTAR server and Microsoft's Internet
  2460.      Information Server, in contrast, try to decide whether a program is an
  2461.      NPH script by examining the first line of script output.
  2462.  
  2463.      CGI.pm supports NPH scripts with a special NPH mode.  When in this mode,
  2464.      CGI.pm will output the necessary extra header information when the
  2465.      _h_e_a_d_e_r() and _r_e_d_i_r_e_c_t() methods are called.
  2466.  
  2467.      The Microsoft Internet Information Server requires NPH mode.  As of
  2468.      version 2.30, CGI.pm will automatically detect when the script is running
  2469.      under IIS and put itself into this mode.  You do not need to do this
  2470.      manually, although it won't hurt anything if you do.
  2471.  
  2472.      There are a number of ways to put CGI.pm into NPH mode:
  2473.  
  2474. into your script:
  2475.      In the uuuusssseeee statement Simply add ":nph" to the list of symbols to be imported
  2476.  
  2477.                use CGI qw(:standard :nph)
  2478.  
  2479.  
  2480.      By calling the nnnnpppphhhh(((()))) method:
  2481.          Call nnnnpppphhhh(((()))) with a non-zero parameter at any point after using CGI.pm
  2482.          in your program.
  2483.  
  2484.                CGI->nph(1)
  2485.  
  2486.  
  2487.      By using ----nnnnpppphhhh parameters in the hhhheeeeaaaaddddeeeerrrr(((()))) and rrrreeeeddddiiiirrrreeeecccctttt(((())))  statements:
  2488.  
  2489.                print $q->header(-nph=>1);
  2490.  
  2491.  
  2492. AAAAUUUUTTTTHHHHOOOORRRR IIIINNNNFFFFOOOORRRRMMMMAAAATTTTIIIIOOOONNNN
  2493.      Copyright 1995,1996, Lincoln D. Stein.  All rights reserved.  It may be
  2494.      used and modified freely, but I do request that this copyright notice
  2495.      remain attached to the file.  You may modify this module as you wish, but
  2496.      if you redistribute a modified version, please attach a note listing the
  2497.      modifications you have made.
  2498.  
  2499.      Address bug reports and comments to:  lstein@genome.wi.mit.edu
  2500.  
  2501.  
  2502.  
  2503.  
  2504.  
  2505.                                                                        PPPPaaaaggggeeee 33338888
  2506.  
  2507.  
  2508.  
  2509.  
  2510.  
  2511.  
  2512. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  2513.  
  2514.  
  2515.  
  2516. CCCCRRRREEEEDDDDIIIITTTTSSSS
  2517.      Thanks very much to:
  2518.  
  2519.      Matt Heffron (heffron@falstaff.css.beckman.com)
  2520.  
  2521.      James Taylor (james.taylor@srs.gov)
  2522.  
  2523.      Scott Anguish <sanguish@digifix.com>
  2524.  
  2525.      Mike Jewell (mlj3u@virginia.edu)
  2526.  
  2527.      Timothy Shimmin (tes@kbs.citri.edu.au)
  2528.  
  2529.      Joergen Haegg (jh@axis.se)
  2530.  
  2531.      Laurent Delfosse (delfosse@csgrad1.cs.wvu.edu)
  2532.  
  2533.      Richard Resnick (applepi1@aol.com)
  2534.  
  2535.      Craig Bishop (csb@barwonwater.vic.gov.au)
  2536.  
  2537.      Tony Curtis (tc@vcpc.univie.ac.at)
  2538.  
  2539.      Tim Bunce (Tim.Bunce@ig.co.uk)
  2540.  
  2541.      Tom Christiansen (tchrist@convex.com)
  2542.  
  2543.      Andreas Koenig (k@franz.ww.TU-Berlin.DE)
  2544.  
  2545.      Tim MacKenzie (Tim.MacKenzie@fulcrum.com.au)
  2546.  
  2547.      Kevin B. Hendricks (kbhend@dogwood.tyler.wm.edu)
  2548.  
  2549.      Stephen Dahmen (joyfire@inxpress.net)
  2550.  
  2551.      Ed Jordan (ed@fidalgo.net)
  2552.  
  2553.      David Alan Pisoni (david@cnation.com)
  2554.  
  2555.      ...and many many more...
  2556.          for suggestions and bug fixes.
  2557.  
  2558. AAAA CCCCOOOOMMMMPPPPLLLLEEEETTTTEEEE EEEEXXXXAAAAMMMMPPPPLLLLEEEE OOOOFFFF AAAA SSSSIIIIMMMMPPPPLLLLEEEE FFFFOOOORRRRMMMM----BBBBAAAASSSSEEEEDDDD SSSSCCCCRRRRIIIIPPPPTTTT
  2559.              #!/usr/local/bin/perl
  2560.  
  2561.              use CGI;
  2562.  
  2563.              $query = new CGI;
  2564.  
  2565.  
  2566.  
  2567.  
  2568.  
  2569.  
  2570.  
  2571.                                                                        PPPPaaaaggggeeee 33339999
  2572.  
  2573.  
  2574.  
  2575.  
  2576.  
  2577.  
  2578. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  2579.  
  2580.  
  2581.  
  2582.              print $query->header;
  2583.              print $query->start_html("Example CGI.pm Form");
  2584.              print "<H1> Example CGI.pm Form</H1>\n";
  2585.              &print_prompt($query);
  2586.              &do_work($query);
  2587.              &print_tail;
  2588.              print $query->end_html;
  2589.  
  2590.              sub print_prompt {
  2591.                 my($query) = @_;
  2592.  
  2593.                 print $query->startform;
  2594.                 print "<EM>What's your name?</EM><BR>";
  2595.                 print $query->textfield('name');
  2596.                 print $query->checkbox('Not my real name');
  2597.  
  2598.                 print "<P><EM>Where can you find English Sparrows?</EM><BR>";
  2599.                 print $query->checkbox_group(
  2600.                                       -name=>'Sparrow locations',
  2601.                                       -values=>[England,France,Spain,Asia,Hoboken],
  2602.                                       -linebreak=>'yes',
  2603.                                       -defaults=>[England,Asia]);
  2604.  
  2605.                 print "<P><EM>How far can they fly?</EM><BR>",
  2606.                      $query->radio_group(
  2607.                              -name=>'how far',
  2608.                              -values=>['10 ft','1 mile','10 miles','real far'],
  2609.                              -default=>'1 mile');
  2610.  
  2611.                 print "<P><EM>What's your favorite color?</EM>  ";
  2612.                 print $query->popup_menu(-name=>'Color',
  2613.                                          -values=>['black','brown','red','yellow'],
  2614.                                          -default=>'red');
  2615.  
  2616.                 print $query->hidden('Reference','Monty Python and the Holy Grail');
  2617.  
  2618.                 print "<P><EM>What have you got there?</EM><BR>";
  2619.                 print $query->scrolling_list(
  2620.                               -name=>'possessions',
  2621.                               -values=>['A Coconut','A Grail','An Icon',
  2622.                                         'A Sword','A Ticket'],
  2623.                               -size=>5,
  2624.                               -multiple=>'true');
  2625.  
  2626.                 print "<P><EM>Any parting comments?</EM><BR>";
  2627.                 print $query->textarea(-name=>'Comments',
  2628.                                        -rows=>10,
  2629.                                        -columns=>50);
  2630.  
  2631.                 print "<P>",$query->reset;
  2632.                 print $query->submit('Action','Shout');
  2633.                 print $query->submit('Action','Scream');
  2634.  
  2635.  
  2636.  
  2637.                                                                        PPPPaaaaggggeeee 44440000
  2638.  
  2639.  
  2640.  
  2641.  
  2642.  
  2643.  
  2644. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  2645.  
  2646.  
  2647.  
  2648.                 print $query->endform;
  2649.                 print "<HR>\n";
  2650.              }
  2651.  
  2652.              sub do_work {
  2653.                 my($query) = @_;
  2654.                 my(@values,$key);
  2655.  
  2656.                 print "<H2>Here are the current settings in this form</H2>";
  2657.  
  2658.                 foreach $key ($query->param) {
  2659.                    print "<STRONG>$key</STRONG> -> ";
  2660.                    @values = $query->param($key);
  2661.                    print join(", ",@values),"<BR>\n";
  2662.                }
  2663.              }
  2664.  
  2665.              sub print_tail {
  2666.                 print <<END;
  2667.              <HR>
  2668.              <ADDRESS>Lincoln D. Stein</ADDRESS><BR>
  2669.              <A HREF="/">Home Page</A>
  2670.              END
  2671.              }
  2672.  
  2673.  
  2674. BBBBUUUUGGGGSSSS
  2675.      This module has grown large and monolithic.  Furthermore it's doing many
  2676.      things, such as handling URLs, parsing CGI input, writing HTML, etc.,
  2677.      that are also done in the LWP modules. It should be discarded in favor of
  2678.      the CGI::* modules, but somehow I continue to work on it.
  2679.  
  2680.      Note that the code is truly contorted in order to avoid spurious warnings
  2681.      when programs are run with the ----wwww switch.
  2682.  
  2683. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  2684.      the _C_G_I::_C_a_r_p manpage, the _U_R_I::_U_R_L manpage, the _C_G_I::_R_e_q_u_e_s_t manpage,
  2685.      the _C_G_I::_M_i_n_i_S_v_r manpage, the _C_G_I::_B_a_s_e manpage, the _C_G_I::_F_o_r_m manpage,
  2686.      the _C_G_I::_A_p_a_c_h_e manpage, the _C_G_I::_S_w_i_t_c_h manpage, the _C_G_I::_P_u_s_h manpage,
  2687.      the _C_G_I::_F_a_s_t manpage
  2688.  
  2689.  
  2690.  
  2691.  
  2692.  
  2693.  
  2694.  
  2695.  
  2696.  
  2697.  
  2698.  
  2699.  
  2700.  
  2701.  
  2702.  
  2703.                                                                        PPPPaaaaggggeeee 44441111
  2704.  
  2705.  
  2706.  
  2707.  
  2708.  
  2709.  
  2710. CCCCGGGGIIII((((3333))))                                                                  CCCCGGGGIIII((((3333))))
  2711.  
  2712.  
  2713.  
  2714.  
  2715.  
  2716.  
  2717.  
  2718.  
  2719.  
  2720.  
  2721.  
  2722.  
  2723.  
  2724.  
  2725.  
  2726.  
  2727.  
  2728.  
  2729.  
  2730.  
  2731.  
  2732.  
  2733.  
  2734.  
  2735.  
  2736.  
  2737.  
  2738.  
  2739.  
  2740.  
  2741.  
  2742.  
  2743.  
  2744.  
  2745.  
  2746.  
  2747.  
  2748.  
  2749.  
  2750.  
  2751.  
  2752.  
  2753.  
  2754.  
  2755.  
  2756.  
  2757.  
  2758.  
  2759.  
  2760.  
  2761.  
  2762.  
  2763.  
  2764.  
  2765.  
  2766.                                                                        PPPPaaaaggggeeee 44442222
  2767.  
  2768.  
  2769.  
  2770.  
  2771.  
  2772.  
  2773.