Modules in the MBFramework
To follow the MBFramework architecture, each form must extend the MBF_Module_Form class which in turn extends the MBF_Module class. After all, a form is a module.
Even though you can write a module as you wish, in order to be consistent, a form module should have at least 3 methods: execute, resetForm and validate. When the page is first requested and the form layout should be displayed, the execute method calls the resetForm method to reset any form values that will be needed to submit the form. One of these values is the form identifier which will differentiate one form from another. This is an important value to set because more than one form may exist on the same page. Once the form is submited, the controller will instantiate the form module and its execute will identify the form and call the process method which will call the validate method. If validation succeeds, the proccess method will continue to process submited data, if not the module will prepare feedback to be presented to the user. This feedback is automatically prepared based on the validation rules you set in the validation form.
For example, the following line of code is present present in the "Contact Us" form:
$this->validateRequiredField('name' , CONTACT_US_ERROR_LABEL_NAME);
and will allow the automatica feedback generation.
Modules, or classes, shouldn't have texts that are used as feedback to users. To clearly separate logic from presentation, MBFramework uses text files thatare specific to each module and to each language you want to have on your site. Even though this structure may add a bit more of work, it allows you to be completely flexible when handling texts for different websites and in different languages. Also, by separating texts by modules, each module will be responsible for loading only the texts that are needed.