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 ofsubmitToURL( )
is the same as the regularForm
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( )
usesForm.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 thegetValues( )
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 ...
Get Actionscript Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.