Machform: Add a Plugin System

CIIAG
ciiag
Published in
2 min readMar 14, 2017

Machform is a great self-hosted form building tool from appnitro similar to wufoo.com. The thing that’s a pain to do is being able to extend and customise the tool. So here’s a quick tutorial on how to create a basic plugin system for Machform.

1. Create Folder Structure

Create a folder called custom in your Machform root folder. Add the following folder structure:

- custom
-- plugins
--- js
--- php
--- css

2. Create Shared Functions / Styles Code

Create the following files inside each of the plugins folders. application.

- js/shared_functions.js
- php/shared_functions.php
- css/shared_styles.php

You can put in here the code needed for functions and styles that apply across the entire application.

4. Add Plugin Code

Modify includes/footer.php and add the code below after line 19 (i.e. after the jquery line checking if it’s loaded). You can also add the same snippet of code to view.php if you want the plugin system to apply to the forms.

/* CUSTOM_CODE Start */							

/* LOAD PLUGINS */

//PHP PLUGINS
require_once("custom/plugins/php/shared_functions.php"); //load shared global functions
$phpFormScript = 'custom/plugins/php/' . $form_id .'_'. basename($_SERVER['PHP_SELF']); //load form specific funtions
if (file_exists($phpFormScript))
require_once($phpFormScript);

//JAVASCRIPT PLUGINS
echo ''; //load shared functions
$jsFormScript = 'custom/plugins/js/' . $form_id .'_'.str_replace(".php","",basename($_SERVER['PHP_SELF'])).'.js'; //load form specific functions
if (file_exists($jsFormScript))
echo '';

//CSS PLUGINS
echo ''; //load shared styles
$cssFormStyle = 'custom/plugins/css/' . $form_id .'_'.str_replace(".php","",basename($_SERVER['PHP_SELF'])).'.css'; //load form specific styles
if (file_exists($cssFormStyle))
echo '';

//ENABLE DEBUG
if ($_GET['debug'] == 1){
echo $phpFormScript . '
'; //DEBUG: output format e.g. custom/plugins/php/47184_edit_entry.php
echo $jsFormScript . '
'; //DEBUG: output format e.g. custom/plugins/js/47184_edit_entry.js
echo $cssFormStyle . '
'; //DEBUG: output format e.g. custom/plugins/css/47184_edit_entry.css
}

/* CUSTOM_CODE End */

In the next Tutorial we will show you how to create a new plugin to modify Machforms behaviour.

--

--

CIIAG
ciiag
Editor for

ICT focused NGO based in the Cook Islands