Recipe 11.17 Submitting a Multipage Form

11.17.1 Problem

You want to submit a multipage form to a URL.

11.17.2 Solution

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

11.17.3 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 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];

// 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 between pages, so there is no need to use session or client variables on the server when using Flash forms.

    Part I: Local Recipes
    Part II: Remote Recipes