| Sample Applications | | Print | |
Now you are ready to rock 'n' rollbasically. The rest of this chapter features two more sample scripts that offer more complexity.
Server-Side Form Data ProcessingThe first demo application features a task that is common on many pagesevaluating form data. We will not check the form data for required fields, because entering this data is hard enough on many mobile devices, and users would most probably not accept error messages after entering data. Instead, we will print out all entered data, converted to WML, therefore providing the script scriptname.php that was used in some of the form examples.
The structure of this script is fairly easy. According to the send method (POST or GET) used, the submitted form data is retrieved from the arrays $_POST or $_GET. Then the output WML is created, and special characters are converted to WML using htmlspecialchars():
Listing 19.13. The Form Data Is Analyzed and Sent Out
<?php
header("Content-type: text/vnd.wap.wml");
switch (strtoupper($_SERVER["REQUEST_METHOD"])) {
case "POST":
$name = $_POST["name"];
$earlier = $_POST["earlier"];
$currently = $_POST["currently"];
break;
case "GET":
$name = $_GET["name"];
$earlier = $_GET["earlier"];
$currently = $_GET["currently"];
break;
default:
$name = $earlier = $currently = "";
}
$name = htmlspecialchars($name);
$earlier = htmlspecialchars(str_replace(";", " and ", $earlier));
$currently = htmlspecialchars($currently);
echo <<<END
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN"
"http://www.wapforum.org/DTD/wml12.dtd">
<wml>
<card id="output" title="output">
<p>
Hello, $name!
<br/>
You have used $earlier.
<br/>
But you are currently using $currently.
</p>
</card>
</wml>
END;
?>
| Users' Comments (0) |
|
No comment posted






