Extension Modules

Extension Modules

Extension modules can be used to add your own form processing features to your form.

 

Examples:

  • You want to load data from a database to the form
  • You want to save the form submission data to a more complex schema of tables in a database.
  • You want to submit the form submission to a web service

and so on.

 

The structure of an extension module

An 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.

 
You can override the functions of FM_ExtensionModule and do custom handling. The functions of the extension module are called at specific points of form processing. For example, the function BeforeFormDisplay() is called just before displaying the form; the function FormSubmitted() is called after the form is submitted and data is validated.

 

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.

ext-module-load-form

 

 

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 form

In 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.

ext-module-add-module

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 modules

The base class for the extension modules - FM_ExtensionModule class contains certain useful member objects.

 

Logging

You 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

 
Example:

$this->logger->LogError("Could not connect to the database")

 

To log an information message, call LogInfo() .

 
Example:
$this->logger->LogInfo("Connected to the remote service")

Form submission variables

The values submitted in the form are available in the member array $this->formvars

 

Example:
$rec = $this->formvars['FirstName'].' '.$this->formvars['LastName'];

Handling errors in an Extension Module

To handle a critical error case in your extension module, make a call to the error_handler object.

Example:

 
$link = mysql_connect('localhost',

                 'mysql_user', 'mysql_password');

 
if(!$link)
{
  $this->error_handler->ShowError(

         "Error connecting to DB:".mysql_error());
  exit;
}

 

Sample Extension Modules

There 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.


InformationSample extension modules

This page has a collection of extension modules: Collection of Extension Modules

you can download and customize any of those custom modules!


 

See Also: