Another Example of Calling a WMLScript


The following example shows a calling sequence WML (Demo.wml) --> WMLScript (Example.wmls) --> WML CGI (Address.pl).




 

This WMLScript code Example.wmls then calls a WML CGI script Address.pl by using the CGI get method. The getVar function of the WMLScript library function WMLBrowser returns the value of the named variable.

 http://people.cs.und.edu/~wenchen/course/handheld/wml/Example.wmls 

extern function  Check( ) {
  var  state   = WMLBrowser.getVar( "state" );
  var  country = WMLBrowser.getVar( "country" );
  WMLBrowser.go (
    "http://people.cs.und.edu/~wenchen/cgi-bin/handheld/wml/Address.pl?s=" + state + "&c=" + country );
}


This WML CGI script Address.pl prints the two arguments from the Web.

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

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

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

# Send 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 Web argument values.
@pairs = split(/&/, $ENV{'QUERY_STRING'});
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 minimal deck
$deck = "

<wml>
 <card><p><br />
   <b>You have entered:</b><br/>
   <b>State:</b> <i>$FORM{s}</i><br/>
   <b>Country:</b> <i>$FORM{c}</i>
 </p></card>
</wml>";

# Send deck
print $deck;