Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions
 Discussion Forums
 HTML, XML, JavaScript...
 Software Reviews
 Editors,Others...
 Top100
 JavaScript Tutorials, ...
 Tutorials
 ASP, CSS, Databases...
 Discussion List
 FAQ, Roundup, Configure ...
 Authoring
 HTML, JavaScript, CSS...
 Design
 Layout, Navigation,...
 Graphics
 Tools, Colors, Images...
 Software
 Browsers, Editors, XML...
 Internet
 Domains, E-Commerce, ...
 WDVL Resources
  Intermdiate, Tutorials,...
 WDVL
 Discussion Lists, Top 100,...
 Technology Jobs


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Top 10 Articles
  1. Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions
  2. JavaScript Tutorial for Programmers
  3. Design
  4. JavaScript Tutorial for Programmers - Objects
  5. JavaScript Tutorial for Programmers - JavaScript Grammar
  6. JavaScript Tutorial for Programmers - Versions of JavaScript
  7. Cascading Style Sheets
  8. JavaScript Tutorial for Programmers - Embedding JavaScript
  9. JavaScript Tutorial for Programmers - Functions
  10. Authoring JavaScript
Domain Name Lookup
Search to find the availability of a domain name. Just enter the complete domain name with extension (.com, .net, .edu)

Maintaining State

Maintaining State

  • Self-referential scripts are very cool and extremely common. However, they do introduce some complexities to your application.

  • One of the most subtle problems introduced by self-referential scripts is the fact that since HTTP is a stateless protocol, a CGI script has no memory of previous connections. Thus, if you want to refer back to a script for a second, the data from the first refernce will be lost.

  • However, you can programmatically give your CGI script memory by saving state in the form of hidden form variables.

  • In other words, you will make sure that all of the form data from one request gets passed to following requests via the HIDDEN form tag.

  • Consider the following code which does just this:

    #!/usr/local/bin/perl
    require "cgi-lib.pl";
    &ReadParse(*form_data);
    print "Content-type: text/html\n\n";
    
    		// Print out form if this is the 
    		// users's first request.  You've seen 
    		// this already!
    
    if ($form_data{'submit'} eq "")
      {
      print qq!
      <HTML>
      <HEAD>
      <TITLE>Testing Form Input</TITLE>
      </HEAD>
      <BODY>
      <FORM METHOD = "POST" 
    		ACTION = "self-refer.cgi">
      <CENTER>
      <TABLE BORDER = "1">
      <TR>
      <TH>First Name</TH>
      <TD><INPUT TYPE = "text" 
    		NAME = "f_name"></TD>
      </TR>
        
      <TR>
      <TH>Last Name</TH>
      <TD><INPUT TYPE = "text" 
    		NAME = "l_name"></TD>
      </TR>
      
      <TR>
      <TH>Email</TH>
      <TD><INPUT TYPE = "text" 
    		NAME = "email"></TD>
      </TR>
         
      </TABLE>
      <P>
      <INPUT TYPE = "SUBMIT" NAME = "submit" 
    		VALUE = "submit">
      </CENTERv
      </FORM>
      </BODY>
      </HTML>!;
      exit;
      }
    
    		// If the user has entered 
    		// only first name,
    		// last name and email, let's 
    		// get phone number
    		// to. But we must make sure 
    		// that we save the
    		// values for first nme, last 
    		// name and email
    		// as hidden form tags.
    
    elsif ($form_data{'submit'} eq "submit")
      {
      print qq!
      <HTML>   
      <HEAD>
      <TITLE>Get More Data While 
    		Remembering Old</TITLE>
      </HEAD>
      <BODY>
      You submitted the following information:
      <P>
      <TABLE BORDER = "1">!;
      
      foreach $key (keys(%form_data))
        {
        print qq!
        <TR>
        <TD>$key</TD>
        <TD>$form_data{$key}</TD>
        </TR>!;
        }
      
    		// Here is where we ask for the 
    		// phone number
      print qq!
      </TABLE>
      <P>
      Thank you very much.  However, we need 
      one more bit of information.
      Please input your phone number below:
      <P>
      <FORM METHOD = "POST" ACTION = "self-refer.cgi"v
      <INPUT TYPE = "TEXT" NAME = "phone">!;
    
    		// Here is were we add the 
    		// hidden variables.
    		// Note that we do not want to 
    		// keep the value
    		// for "submit" cause we are 
    		// going to create a
     		// new submit button with a new 
    		// VALUE argument 
    		// so that we know which request 
    		// is coming in.
      
      foreach $key (keys(%form_data))
        {
        if ($key ne "submit")
          {
          print qq!
          <INPUT TYPE = "HIDDEN" NAME = "$key" 
                    VALUE = "$form_data{$key}">!;
          }
        }
       
      print qq!
      <INPUT TYPE = "SUBMIT" NAME = "submit" 
                VALUE = "Final Submit">
      </FORM>
      </BODY>
      </HTML>!;
      }
    
    		// If the user clicked a 
    		// button with "Final Submit" 
    		// then the above routines 
    		// would have both returned 
    		// false and we can assume that 
    		// the user has entered the 
    		// phone number, so we handle it.
      
    else 
      {
      print qq!
      <HTML>
      <HEAD>
      <TITLE>Testing Form Input</TITLE>
      </HEAD>
      <BODY>
      <TABLE>!;
        
      foreach $key (keys(%form_data))
      {
      print qq!
      <TR>
      <TD>$key</TD>
      <TD>$form_data{$key}</TD>
      </TR>!;
      }  
      
      print qq!
      </TABLE>
      </BODY>
      </HTML>!;
      }    
    

Additional Resources:

Self-Referential Scripts
Table of Contents
Exercise Four


Up to => Home / Authoring / Scripting / Tutorial




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers