Welcome to Developer's Home Friday, April 18, 2014
Home - DevelopersHome.com

Posting Data When an Event Occurs


Preferences - Do not show ads

In the earlier WML examples, the <go> and <postfield> tags are enclosed in the <anchor></anchor> tag pair. This creates an anchor link for posting the form data. WML also allows you to enclose the <go> and <postfield> tags in the <onevent></onevent> tag pair. This means you can post some data to the server when an event occurs.

For example, if you want to post a form when the user selects an option of a selection list, you should place the <go> and <postfield> tags in the onpick event handler of the corresponding option. The following WML example demonstrates how to do this:


(sendDataEg2.wml)

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

<wml>
  <card id="card1" title="WML Form">
    <onevent type="onenterforward">
      <refresh>
        <setvar name="my_temp_id" value="123456"/>
      </refresh>
    </onevent>

    <p>
      Hello, welcome to our WML tutorial.<br/>

      What's your name?<br/>
      <input name="myName"/><br/>

      Are you a boy or a girl?<br/>
      <select name="myGender">
        <option value="Boy">I am a boy</option>
        <option value="Girl">I am a girl</option>
      </select><br/>

      Which part of our WML tutorial do you like?<br/>
      <select name="favorite_tutorial_part" multiple="true">
        <option value="Part 1">Part 1</option>
        <option value="Part 2">Part 2</option>
        <option value="Part 3">Part 3</option>
        <option value="Part 4">Part 4</option>
      </select><br/><br/>

      Post Data or Reset Form?<br/>
      <select name="post_form">
        <option>
          <onevent type="onpick">
            <go method="get" href="processing.asp">
              <postfield name="name" value="$(myName)"/>
              <postfield name="gender" value="$(myGender)"/>
              <postfield name="tutorial_part" value="$(favorite_tutorial_part)"/>
              <postfield name="temp_id" value="$(my_temp_id)"/>
            </go>
          </onevent>
          Post Data
        </option>


        <option>
          <onevent type="onpick">
            <refresh>
              <setvar name="myName" value=""/>
              <setvar name="myGender" value=""/>
              <setvar name="favorite_tutorial_part" value=""/>
            </refresh>
          </onevent>
          Reset Form
        </option>
      </select>
    </p>
  </card>
</wml>


The following screenshots show what you will see if you open the above WML file in some mobile phone browsers. To post the form to the server, select the "Post Data" option of the last selection list.









Sony Ericsson T610











Sony Ericsson T68i








Nokia Mobile Browser 4.0


If you want the WAP browser to post some data to the server automatically when a user navigates to a certain card in the forward direction, you need to place the <go> and <postfield> tags in the onenterforward event handler of the card, like this:


<card ...>
  <onevent type="onenterforward">
    <go method="get" href="processing.asp">
      <postfield name="name" value="$(myName)"/>
      <postfield name="gender" value="$(myGender)"/>
      <postfield name="tutorial_part" value="$(favorite_tutorial_part)"/>
      <postfield name="temp_id" value="$(my_temp_id)"/>
    </go>
  </onevent>
...
</card>


Similarly, to post some data to the server automatically when a user navigates backwards to a card or after a certain period of time, place the <go> and <postfield> tags in the onenterbackward event handler and the ontimer event handler respectively.


Page 48 of 50 Previous Page | Next Page
Contents at a Glance
Print this Web Page | | Back to Top
Custom Search

Feedback Form (Expand)

What do you think about this web page?






WML Tutorial Table of Contents WML Tutorial Contents at a Glance Preferences - Change Color Scheme Preferences - Do Not Show Ads Previous Page Next Page