German German English English

 Table or div <<    ^ MPForm Help pages ^    >> Loops in Forms

MPForm Documentation: Private Functions

Level of difficulty: C 

A module for LEPTON can solve many tasks for many users. But some customers do have wishes or needs which require special functionalities. Even on the same web site multiple forms might exist, which need to react differently. To be able to act in a flexible way, interfaces to some private functions are build into MPForm. Those functions reside in the file private.php. The advantage of the bundling of the own (private) program code into a single file should be obvious: Otherwise when upgrading the module, you would need to compare the differences of old and new source code before performing the upgrade, and need to copy each change onto the correct place in the new files. By outsourcing all changes into the file private.php you can skip this work. The file private.php will not be updated when upgrading the module. You need to pick up updates to the prepared examples by yourself from the file private.default.php!

Currently, the following private functions are defined currently:

function private_function_before_new_form($section_id)
Will be called before a form will be assembled. Here you can, for instance, set the current date in a field.
function private_function_before_email($section_id, &$html_data_user, &$html_data_site)
Will be called after a form has been submitted successfully, but before it will be saved or sent by email. Here you can, change the message text.
There are two versions, one for the site owner and one for the user who has submitted the form.
private_function_after_email($section_id, &$html_data_site, &$mpform_fields)
Will be called after a form has been submitted and email has been sent successfully, but before data is saved to the database. If you need to postprocess the submitted values for later use and you want to keep the original format in the email, this is the place to do this transformation.
Again, there are two versions: On the one hand the SQL statements for the results table and on the other hand the HTML version for the submissions table.
Will be called after a form has been submitted and saved successfully. Here you can, for instance, change the following page dynamically.

When the function should not do the same action for every form, you should first check the variable $section_id and only when it matches, the required actions should be run. This variable is the only argument which is provided as parameter to the private functions.

The return value should be a Boolean type. Currently, private_function_before_new_form does not use it. For all other private functions a return value of TRUE means that execution was successful and the program flow may continue. FALSE means that someting went wrong and execution is aborted at this point.

On the next page an example for private functions is given: How to create a loop within a multipage form