O'Reilly logo

Actionscript Cookbook by Joey Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

11.17. Submitting a Multipage Form

Problem

You want to submit a multipage form to a URL.

Solution

Create and invoke a submitToURL( ) method for the custom MultiPageForm class.

Discussion

Once you have created the getValues( ) and submitToURL( ) methods of the Form class (see Recipe 11.13), you can leverage them to create versions of the same methods for the MultiPageForm class. Add the following code to your Form.as file for easy inclusion in other projects:

// The multipage version of submitToURL(  ) is the same as the regular Form version.
MultiPageForm.prototype.submitToURL = function (url) {
  var lv = new LoadVars(  );
  var vals = this.getValues(  );
  for (var item in vals) {
    lv[item] = vals[item];
  }
  lv.send(url);
};

// MultiPageForm.getValues(  ) uses Form.getValues(  ) to create an object with the
// elements of all the form pages and their values.
MultiPageForm.prototype.getValues = function (  ) {
  var obj = new Array(  );
  var formVals, elem;

  // Call the getValues(  ) method of each form page and add those results to the
  // multipage values associative array.
  for (var i = 0; i < this.forms.length; i++) {
    formVals = this.forms[i].getValues(  );
    for (elem in formVals) {
      obj[elem] = formVals[elem];
    }
  }
  return obj;
};

The HTML paradigm for multipage forms requires server-side persistence (or client-side cookies) involving saving values to session or client variables. This is necessary with HTML because HTTP is a stateless environment. Flash, however, is stateful; ActionScript can remember values ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required