SolutionsTools & SDKSupportForums Register



Quick Links
 
WALL Tutorial: Forms
 
 
By Luca Passani

In the last two parts of our tutorial, I introduced menus. Menus are important, since mobile users should not be required to think too much when using a mobile application. For this reason, you should do whatever you can to avoid requiring users to enter words and numbers. Having said that, there will be cases when clicking links simply won't cut it. For example:
  • capturing a person's name
  • asking for a credit card number
  • requesting ZIP code
  • entering the title of a song
These are just random examples of data which users will be required to painfully enter key press after key press. That's where "forms" become necessary. A form is a set of input elements such as radio-buttons, checkboxes, push buttons, combo-boxes and text fields. Forms allow users to pass data to the web server.

I am assuming that you are familiar with WML and XHTML Forms or, at the very least, with HTML forms as found on the big web. If not, please refer to the resources in the reference section at the end of this article. As is customary, before we delve into forms, a little preaching is required.

Luca's "Usability" Preach
Entering data on a mobile device is way more difficult and time-consuming than doing it on the web. For this reason, reproducing a web form into a wireless application is not a good idea. You should be creative and find ways to minimize user input. Here are a few tricks:
  • use input masks ('format' attribute) to turn the keyboard in numeric mode when numbers are required.
  • split complex forms in parts (wizard) to help users focus on smaller tasks
  • use links to let users confirm previous choices with one click.
Let me make the point clear with one example. Imagine that you need to collect your user's credit card number. A typical web application would legitimately implement such a form as in Figure 1:


Figure 1: Web form to collect credit cad information

While such a form could also be implemented the same way on a mobile device, this would be far from optimal from a usability viewpoint. A more sensible way to collect the same data from a mobile user could be to split it up in the following steps:


Figure 2a, 2b and 2c: Credit card form made usable for wireless users.

(2a) There are only a few credit card brands, so let users select theirs with one click.

(2b) Once we know the credit card type, we can pre-fill the card number field with the first two digits (e.g., 37 = American Express). Of course, you can use input masks to turn the keypad into numeric mode and greatly simplify data input.

(2c) For dates, the year and month are better modeled as text fields in numeric mode, rather than forcing the user to do a whole lot of scrolling to detect month and year through a combo-box.

Now I'll step down off of my soapbox so we can see how WALL supports forms.

HTML Forms
If you target WAP2 devices, forms are implemented in a standard way that you may do without WALL.
---------------------------------------------------------------------
<form name="data" action="getdata" method="get">
 <p>
Your Name:
<input type="text" name="name" value="">   
Male or Female.<br/>
M:<input type="radio" name="gender" value="Female" selected="selected"> 
F:<input type="radio" name="gender" value="Male">
<br/>
  <input type="submit" value="Send" />
 </p>
</form>
---------------------------------------------------------------------
Listing 1: XHTML-MP Form

Not only is this guaranteed to work on WAP2 devices, but it will work on Imode CHTML devices too (you may want to replace <br> with <wall:br/>, though). One little note of caution is about those <p>/</p> tags. They must be there in the name of XHTML-MP conformance. If you don't use them, your form will still work on most browsers, but it will fail completely on some (notably, the SonyEricssons using the Teleca browsers).

Because of these well-formdness headaches, you may still want to use <wall:form>/</wall:form> instead of <form><p>/</p></form> while coding the form exactly as shown in Listing 1:
<wall:form name="data" action="getdata" method="get">
Your Name:
  ...

In addition to ensuring well-formdness, this will protect users who navigate to your site with a WML 1.X browser from receiving the error page (and you come across these browsers anyway since there are still many millions in circulation).

Please note that WALL forms are on the same level as Blocks, Menus and Cool Menus, which means that you should not nest them into one another. Things get more complicated when we need to support WML too.

Bringing WML Into The Picture
WML forms are structurally different from HTML. First, there's no "form" tag. Widgets can be placed randomly in a card. There's no submit button in WML (at least not in WML 1.1). The role of submit buttons is assumed by hyperlinks, which can post the values of the widgets by lining up WML variables in their query string. Just refer to the WML Reference if you want to know more about how forms work in WML.

In this context, finding a common denominator between HTML and WML forms is not simple. WALL did it by introducing a lot of magic and a few restrictions:
  • Forms in "WML Compatibility mode" can contain input fields, password, single-choice select-option, hidden fields and one submit button.
  • submit buttons are rendered as either softkeys or hyperlinks for WML (i.e. this is a great example of intra-markup optimization).
  • Multiple selection widgets are not allowed (the format of the query string would vary from one mark-up to the other).
These restrictions are not really major, since you can always branch your JSPs for specific needs (possibly using the JSTL). Also, increasing the complexity of WALL forms would be a good example of diminishing returns: lots of extra complexity to manage for a very tiny return.

Time for an Example
So, let's see a form in WML Compatibility mode in action:
---------------------------------------------------------------------
1  <%@ taglib uri="/WEB-INF/tld/wall.tld" prefix="wall" %>
2  <wall:document><wall:xmlpidtd />
3
4  <wall:head>
5     <wall:title>WALL Form</wall:title>
6  </wall:head>
7
8  <wall:body>
9 
10 Verify identity:<wall:br/>
11  <wall:form action="/validate" method="get" enable_wml="true">
12 Pin Code:
13    <wall:input type="text" name="pincode" 
                maxlength="4" value="" format="NNNN" />
14    <wall:br />
15 Remember me:
16    <wall:select title="remember" name="remember">
17       <wall:option value="yes" selected="selected">Yes</wall:option>
18       <wall:option value="no">No</wall:option>
19       <wall:option value="week">One Week</wall:option>
20       <wall:option value="month">One Month</wall:option>
21   </wall:select>
22   <wall:br />
23   <wall:input type="hidden" name="session" value="dks3244afsk42" />
24
25   <wall:input type="submit" value="Go" />
26  </wall:form>
27 </wall:body>
28 </wall:document>
---------------------------------------------------------------------
Listing 2: WALL Form

- Nothing new up to line 11. The 'enable_wml' attribute tells WALL that we want to support WML devices and we know what you are doing. If we omit that attribute (or set it to false), WML devices will be greeted by a message that their device is not supported.

- line 13 is an 'input' element. As you can see, this is pure HTML, so there's not much you need to learn here. The only surprise is the 'format' attribute. It does not live in HTML, but since it is a friend (and a very useful one!) it was welcome to join WALL. We'll see how it is out to work.

- lines 16 through 26 are new...or are they pure HTML again? You are probably more curious to see what this becomes for WML devices than getting those lines explained!

Let's look at the code then. CHTML is no surprise. Our friend the 'format' attribute got down to work and turned into a nice 'istyle="4"'. While not exactly the same as requiring 4 digits, this construct will put the keyboard of Imode devices into numeric mode. This is very helpful for users.

---------------------------------------------------------------------
<html>
<head>
 <title>WALL Form</title>
</head>

<body>

Verify identity:<br>
 <form action="/validate" method="get">
Pin Code:
   <input type="text" name="pincode" 
            value="" maxlength="4" istyle="4">
<br>
Remember me:
   <select name="remember" title="remember">
           <option value="yes" selected>Yes</option>
           <option value="no">No</option>
           <option value="week">One Week</option>
           <option value="month">One Month</option>
   </select>
<br>
  <input type="hidden" name="session" value="dks3244afsk42">

  <input type="submit" value="Go" />
 </form>
</body>
</html>
---------------------------------------------------------------------
Listing 3: CHTML

XHTML-MP is also no surprise. Here WALL will use either 'format="NNNN"' or 'style="-wap-input-format: 'NNNN'"' depending on what the device understands ('xhtml_format_as_css_property' and 'xhtml_format_as_attribute' are the relevant WURFL capabilities).

---------------------------------------------------------------------
 <form action="/validate" method="get">
 <p>
Pin Code:
   <input type="text" name="pincode" value="" 
          style="-wap-input-format: 'NNNN'" maxlength="4"/>
<br/>
Remember me:
   <select name="remember" title="remember">
           <option value="yes" selected="selected">Yes</option>
           <option value="no">No</option>
           <option value="week">One Week</option>
           <option value="month">One Month</option>
   </select>
<br/>
  <input type="hidden" name="session" value="dks3244afsk42"/>

  <input type="submit" value="Go" />
  </p>
</form>
---------------------------------------------------------------------
Listing 4: XHTML

Of course, things get much more interesting when we need to render for WML devices. WALL needs to do some magic to create WML variables behind the scenes and build a hyperlink that will post the values to the server. Observe how hidden fields need a slightly different treatment:

---------------------------------------------------------------------
<wml>
<head>
 <meta name="taglib" content="WALL" />
</head>
<card id="w" title="WALL Form">
<p>
Verify identity:
</p>
 <p>
Pin Code:
   <input type="text" name="pincode" value="" format="NNNN" maxlength="4"/>
<br/>
Remember me:
   <select name="remember" title="remember">
           <option value="yes">Yes</option>
           <option value="no">No</option<
           <option value="week">One Week</option>
           <option value="month">One Month</option>
   </select>
<br/>  
<anchor>Go
 <go href="/validate" method="get">
   <postfield name="session" value="dks3244afsk42" />
   <postfield name="pincode" value="$pincode" />
   <postfield name="remember" value="$remember" />
 </go>
</anchor>
 </p>
</card>
</wml>
---------------------------------------------------------------------
Listing 5: WML (Flavor 1)

If you have programmed WML in the past, you are probably aware of the differences in WML support by different devices. Some devices offer better usability when navigation takes advantage of softkeys ('softkey_support' capabilities). WALL recognizes this and produces optimized WML for those devices:

---------------------------------------------------------------------
 <p>
Pin Code:
   <input type="text" name="pincode" value="" format="NNNN" maxlength="4"/>
<br/>
Remember me:
   <select name="remember" title="remember">
           <option value="yes">Yes</option>
           <option value="no">No</option>
           <option value="week">One Week</option>
           <option value="month">One Month</option>
   </select>
<br/>  
<do type="accept" label="Go">
 <go href="/validate" method="get">
   <postfield name="session" value="dks3244afsk42" />
   <postfield name="pincode" value="$pincode" />
   <postfield name="remember" value="$remember" />
 </go>
</do>
---------------------------------------------------------------------
Listing 5: WML (Flavor 2)

Conclusions
Doing forms in WAP 2 and Imode is not difficult. Things get trickier if you want to support WML too, since WML is a basically different mark-up. WALL can help there. As long as you keep your forms simple, you can still get away with a unique set of JSPs for all of your wireless. And, if you need more complex constructs, WALL can still be there to help, thanks to the power of JSTL, which we will cover in the next installment of this tutorial.

Enjoy!

References
XHTML MP Tutorial (Forms)
WML Reference
WAP Usability



 
Copyright © 2000-2008 Openwave Systems Inc.    About Us  |  Openwave  |  Terms & Conditions  |  Privacy Policy  |  Update Profile