WML - Server Side Scripts

Advertisements


If you already know how to write server side scripts for Web Application, then for you this is very simple to write Server Side program for WML applications. You can use your favorite server-side technology to do the processing required by your mobile Internet application.

At the server side, the parameter name will be used to retrieve the form data.

Consider the following example from previous chapter to submit name, age and sex of a person:

<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN"
"http://www.wapforum.org/DTD/wml12.dtd">

<wml>

<card id="card1" title="WML Form">
<p>
   Name: <input name="name" size="12"/>
   Sex : <select name="sex">
      <option value="male">Male</option>
      <option value="female">Female</option>
      </select>
   Age :  <input name="age" size="12" format="*N"/>
   <anchor>
      <go method="get" href="process.php">
          <postfield name="name" value="$(name)"/>
          <postfield name="age" value="$(age)"/>
          <postfield name="sex" value="$(sex)"/>
      </go>
      Submit Data
    </anchor>
</p>
</card>

</wml>

WML and PHP

Now, we can write a server side script to handle this submitted data in using either PHP, PERL, ASP or JSP. I will show you a server side script written in PHP with HTTP GET method.

Put the following PHP code in process.php file in same directory where you have your WML file.

<?php echo 'Content-type: text/vnd.wap.wml'; ?>
<?php echo '<?xml version="1.0"?'.'>'; ?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN"
"http://www.wapforum.org/DTD/wml12.dtd">

<wml>
  
  <card id="card1" title="WML Response">
    <p>
      Data received at the server:<br/>
      Name: <?php echo $_GET["name"]; ?><br/>
      Age: <?php echo $_GET["age"]; ?><br/>
      Sex: <?php echo $_GET["sex"]; ?><br/>
    </p>
  </card>

</wml>

If you are using HTTP POST method, then you have to write PHP script accordingly to handle received data. While sending output back to the browser, remember to set the MIME type of the document to "text/vnd.wap.wml".

This way, you can write full fledged Web Application where lot of database transactions are involved.

You can use PERL CGI Concepts to write a dynamic WAP site.



Advertisements
Advertisements