Slide 11.14: WML input fields (cont.)
  Slide 11.16: WML GO and POSTFIELD tags
  Home


WML Input Fields (Cont.)


The following CGI (Common Gateway Interface) Perl script is for the WML script in the previous slide. It simply prints the three input data from the WML interface. The top part of a WML CGI Perl could be found from here.

CGI is a web technology that enables a client web browser to request data from a program executed on the web server. CGI specifies a standard for passing data between the client and the program. The programming language Perl is often associated with CGI, but CGI programs can be written in any scripting language, as long as that language can be executed on the system such as Java and C/C++.

 http://people.cs.und.edu/~wenchen/cgi-bin/handheld/wml/Input.pl 

#!/usr/bin/perl
#
# This script must be located in the directory of /cgi-bin .
#

# Send the Content-type.
print "Content-type: text/vnd.wap.wml \n\n";

# Send the WML header information.
print "<?xml version=\"1.0\"?>\n";
print "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.2//EN\""
   . " \"http://www.wapforum.org/DTD/wml_1.2.xml\">\n";

# Retrieve the Web argument values from the standard input.
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
  ($name, $value) = split(/=/, $pair);
  $value =~ tr/+/ /;
  $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  $value =~ s/~!/ ~!/g;
  $FORM{$name} = $value;
}

# Define a minimal deck.
$deck = "

<wml>
 <card title='Input Results'>
  <p><br/>
   <b>You have entered:</b><br/>
   Name: <i>$FORM{cgi_name}</i><br/>
   Age: <i>$FORM{cgi_age}</i><br/>
   Sex: <i>$FORM{cgi_sex}</i><br/><br/>
  </p>
 </card>

</wml>";

# Send the deck.
print $deck;