Connecting to the Server

In WML, you can also create forms, which are much like HTML forms. The data in a WML form is encoded just as in HTML, so it can be uploaded to CGI scripts (note that not all microbrowsers will support forms).

Here's an example. In this case, I'll ask for user comments and send them back to a CGI script named comments.cgi. To start, I create a <do> element with the label Upload Data, setting its method attribute to "post" , and its href attribute to the URI to post to, "http://www.starpowder.com/comments.cgi" , just as you might in an HTML form:

 <?xml version="1.0"?>  <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 2.0//EN"     "http://www.wapforum.org/dtd/wml20.dtd" > <wml>     <card id="Card1" title="Uploading">         <p align="center"><b>Uploading</b></p>         <do type="accept" label="Upload data">  <go method="post"   href="http://www.starpowder.com/comments.cgi">   .   .   .   </go>  .             .             . 

All that's left is to indicate the value of the data to upload and how to name that data. You do that with the <postfield> element's name and value attributes. In this case, I'll upload the text from a text field named comments, like this:

 <?xml version="1.0"?>  <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 2.0//EN"     "http://www.wapforum.org/dtd/wml20.dtd" > <wml>     <card id="Card1" title="Uploading">         <p align="center"><b>Uploading</b></p>         <do type="accept" label="Upload data">             <go method="post"                 href="www.starpowder.com/comments.cgi">  <postfield name="comments" value="$(comments)"/>  </go>         </do>         <p>         Please give us your comments:  <input type="text" name="comments"/>  </p>     </card> </wml> 

And that's all it takes. The CGI script can now read the uploaded data as it would from any HTML document. Note that when you send back a response, you should format that response in WML, which means setting the content pe er item to the WML MIME type "text/vnd.wap.wml" .



Real World XML
Real World XML (2nd Edition)
ISBN: 0735712867
EAN: 2147483647
Year: 2005
Pages: 440
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net