WML: An Introduction - Would You Like My Special Offer
(Page 4 of 6 )
In this next example, I’ll show you how WMLScript can further enhance the interaction between your WAP site and the end-user. We’ll first start by building the form interface that will be presented to the user:
<wml>
<card id="main" title="Special Officer">
<p>
Enter your name:<br />
<input type="text" name="user_name" />
<do type="button" label="Submit">
<go href="example02.wmls#prompt_user()" />
</do>
</p>
</card>
<card id="result" title="Thank you!">
<p>
You chose $result accept the "Special Offer". Thank you!<br />
</p>
<p>
An email has been sent to confirm your $email.
</p>
</card>
</wml>
We’ve created two cards in our deck. The first, Special Offer, presents a form to the user in which they can enter their name, followed by a submit button. This is how the form looks to the user:

When the submit button is pressed, our form calls the page indicated in our <go> tag; in this case, example02.wmls#prompt_user(), which calls the prompt_user() function we’re now going to create:
extern
function prompt_user(){</p>
<p align="left"> </p>
<p align="left"> var user_name = WMLBrowser.getVar("userName");
var prompt = "Would you like to accept our "Special Offer", " + user_name + "?";
var yes = "Yes";
var no = "No";
var result = Dialogs.confirm(prompt,yes,no);</p>
<p align="left"> </p>
<p align="left"> if (result == true){
WMLBrowser.setVar("result", "to");
WMLBrowser.setVar("email", "acceptance!");
WMLBrowser.go("mailto:frank@developershed.com?from=Special Offer Administrator&subject=Special Offer&body=You accepted the special offer. Thank you!");
WMLBrowser.go("example02.wml#result");</p>
<p align="left"> </p>
<p align="left"> } else {</p>
<p align="left"> </p>
<p align="left"> WMLBrowser.setVar("result", "not to");
WMLBrowser.setVar("email", "refusal.");
WMLBrowser.go("mailto:frank@developershed.com?from=Special Offer Administrator&subject=Special Offer&body=Thank you for considering our offer. Stay tuned for new offers!");
WMLBrowser.go("example.wml#result");
}
}
The prompt_user() function is fairly straightforward. We first make use of the extern keyword to indicate that the function is available to an outside file, in our case example02.wml. We then create our local variables, which will be used to create the user prompt. Our result variable will hold the returned value sent from the user confirmation (a Boolean value).

We then test to see if our result is true. We then test to see if result is true or false. Next, we set the value to our variables (result and email) in the “result” card (see example02.wml), which will be displayed to the user after sending a confirmation email indicating the users selection (yes or no).
The final output displayed to the user is shown below:

Next: Welcome Aboard! >>
More Web Services Articles
More By Frank Manno