Slide 11.19: WML selection (cont.)
  Slide 11.21: WML tasks
  Home


WML Selection (Cont.)


This example shows the user can select more than one item by setting the tag <select>'s attribute multiple="true" .




 

The multiple selected items sent to the CGI Perl script are separated by semicolons ‘;’, for example, the variable
   $FORM{cgi_items} = "xml;wap";
if the user selected the XML and WML tutorials. The following code can be used to separate the selected items and put them in an array @items:
   @items = split(/;/, $FORM{cgi_items});
A loop is then used to access each selected item:
   foreach $item (@items) {  ...  }

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

#!/usr/bin/perl

# 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;
}

# Print the top part of the resulting page.
print <<EndofWML;
<wml>
 <card title='Select Results'>
  <p><br/>
   You have selected:<br/>
EndofWML

@items = split(/;/, $FORM{cgi_items});
foreach $item (@items) {
  print ("<i>$item</i><br/>");
}

# Print the last part of the resulting page.
print <<EndofWML;
  <br/></p>
 </card>
</wml>
EndofWML