Extension Modules |
Extension modules can be used to add your own form processing features to your form.
Examples:
and so on.
The structure of an extension moduleAn extension module is written in PHP. You should be familiar with the syntax of PHP to write extension modules.
Your extension module should extend FM_ExtensionModule class.
The extension module below loads the form (the field 'Name') <?PHP
class MyCustomLoadingModule extends FM_ExtensionModule { function BeforeFormDisplay(&$formvars) { $formvars["Name"] = "Default Name"; return true; } }
?>
The code above loads a field 'Name' with a default value. To see this code in action, put the code above in a file (say mymodule.php) Then Enable 'extension modules' in the 'Form processing options' page, and add the file in the 'Extension Modules' page.
The field "Name" will have the value "Default Name" when the form is loaded.
Of course, you can have more complex logic in your extension module.
The Function Reference contains the list of all the functions that you can override in your custom module.
Integrating the module with your formIn Simfatic Forms, first enable extension modules in the Form Processing Options Page.
In the 'Extension Modules' Page you can load your extension modules. Press the 'Add Module' button and select the file that you have created.
You can add any number of extension modules to your form. The overrides will be called one by one (in the order they appear in the 'Extension Modules' page )
Features available to the extension modulesThe base class for the extension modules - FM_ExtensionModule class contains certain useful member objects.
LoggingYou can use the Simfatic Forms standard logger in your extension module. The logged messages will appear in the log if you enable logging in your form. (Enable logging in 'Form Processing Options' page)
To Log an error, call LogError()function $this->logger->LogError("Could not connect to the database")
To log an information message, call LogInfo() . Form submission variablesThe values submitted in the form are available in the member array $this->formvars
Example: Handling errors in an Extension ModuleTo handle a critical error case in your extension module, make a call to the error_handler object. Example: 'mysql_user', 'mysql_password'); "Error connecting to DB:".mysql_error());
Sample Extension ModulesThere are some sample Extension Modules in the Simfatic Forms Installation folder(usually "C:\Program Files\Simfatic Solutions\SimfaticForms" ). Open the sub-folder "scripts\server\ExtensionModuleSamples". You will find some sample extension modules. The same folder contains some form template files as well. These sample modules will serve as a good starting point.
See Also:
|