Online
 
Thursday, 20 November 2008
 
 

Sample Applications | Print |  E-Mail
 

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 Processing

The 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;
?>
This entry was posted on . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a comment.
Users' Comments (0)

Comment an article
  Name
  E-mail
   Title
Available characters: 4000
 Notify me of follow-up comments
This image contains a scrambled text, it is using a combination of colors, font size, background, angle in order to disallow computer to automate reading. You will have to reproduce it to post on my homepage
Enter what you see:

No comment posted

Jumbo Coklat
 
Top! Top!