Skip to main content

Add Custom Functionality to Submission

Many of you may have experience with Magento event system, so this help page will be easy to get into.

Lets create observer function for WebForms that dumps submitted result into XML file.

We will be creating new extension called WebFormsProcessResult.

WebFormsProcessResult file structure

It contains 4 files in total.

├── code
│ └── community
│ └── VladimirPopov
│ └── WebFormsProcessResult
│ ├── etc
│ │ ├── config.xml
│ │ └── system.xml
│ └── Model
│ └── Observer.php
└── etc
└── modules
└── VladimirPopov_WebFormsProcessResult.xml

app / etc / modules / VladimirPopov_WebFormsProcessResult.xml

This file registeres and enables extension in Magento

<?xml version="1.0"?>

app / code / community / VladimirPopov / WebFormsProcessResult

This folder contains main extension files.

etc / config.xml

In this file we are registering model for our extension and hook it to WebForms event "webforms_result_submit".

<?xml version="1.0"?>
<title>Allow Everything</title>

etc / system.xml

This file holds configuration options for our extension. WebFormsProcessResult has turn on/off switch.

<?xml version="1.0"?>
<processresult translate="label comment">
<label>Results Post Processing</label>
<enable translate="label comment">
<![CDATA[Results will be additionally processed by custom function]]>
<label>Enable results post processing</label>

You`ll notice new block on Web-forms > Forms Settings page.


Model / Observer.php

Here we define model that has method of exporting submited result to xml file.

class VladimirPopov_WebFormsProcessResult_Model_Observer{

public function exportXML($observer){
if(!Mage::getStoreConfig('webforms/processresult/enable')) return;

$webform = $observer->getWebform();

* Check web-form code
* if($webform->getCode() != 'myform') return;

$result = Mage::getModel('webforms/results')->load($observer->getResult()->getId());
$xmlObject = new Varien_Simplexml_Config($result->toXml());

// generate unique filename
$destinationFolder = Mage::getBaseDir('media') . DS . 'webforms' . DS . 'xml';
$filename = $destinationFolder . DS . $result->getId().'.xml';

// create folder
if (!(@is_dir($destinationFolder) || @mkdir($destinationFolder, 0777, true))) {
throw new Exception("Unable to create directory '{$destinationFolder}'.");

// export to file


$destinationFolder - variable that sets folder where result is stored. We will be creating files in media / webforms / xml folder.

$filename - is complete path to the file. For example media / webforms / xml / 123.xml.

Make sure media folder is writable!

Thats it! Feel free to modify this extension, experiment and add required post processing functionality to WebForms.

You can download sources here.