Jasper

Conclusions

Preprocessing forms in this manner could be considered the preferred method, even when not strictly necessary. A form's functionality is still wholly contained within the form class, after all. Now the form submittal is handled at the preprocessing stage, however, with the only the display of the form being handled at the processing stage.

This approach has a pleasing symmetry, with the contents of the form classes themselves becoming more organised, too. What asymmetry there is is absorbed by the global properties array in the form of temporary variables. If conventions are observed, however, all is made good once the form has been displayed.

Dozens of preprocess(...) methods can be added to the PreProcess class constructor in this manner, with the overhead associated with calling them unnecessarily each time the a page is displayed being offset by the convenience that this approach brings.

The last point to note is that this approach easily adapts to a series of forms. Consider several forms to gather account details, then personal details, show a preview page and then a confirmation page, for example. On the successful completion of each form, the next page is shown. Simply having the preprocess(...) method return a boolean value will allow this functionality to be handled easily in the PreProcess class constructor:

class PreProcess
{
    function PreProcess ( array props )
    {
        if ( AccountDetails.preprocess( props ) )
        {
            props{ "FORM.page" } = "personal_details";
        }

        if ( PersonalDetails.preprocess( props ) )
        {
            props{ "FORM.page" } = "preview_details";
        }

        if ( PreviewDetails.preprocess( props ) )
        {
            props{ "FORM.page" } = "confirm_details";
        }

        if ( ConfirmDetails.preprocess( props ) )
        {

        }
    }
}

Convention here is that the value of the 'page' form variable is only ever altered from within the PreProcess class constructor and only ever in response to a preprocess(...) method of a form related class returning 'true'. Each such trail can be abstracted to a private function within the PreProcess class and no return values need be considered.

The very last point to make is that if completion of the form results in a new page being displayed no matter whether the form's intended action has been successful or not, some slight of hand is needed to handle the possible cases at the preprocess stage. A tip is provided for this eventuality and a link to it is provided in the related links section immediately below.

Related links

Last updated: Sunday, 23rd October 2011, 07:14 PM

User comments:

There are none.

Leave a comment:

Display name Email address Content
Enable HTML content
PreviewSubmit