Wednesday, April 24, 2013

Contao 2.x Hooks Tutorial (processFormData)

Contao Hooks are functions that get triggered on certain events. For a list of available hooks take a look at the Contao Documentation.

Here is a quick tutorial on how to setup a hook for processing form data entered by members in your website.

Folder Structure

Create the following files and folder inside TL_ROOT/system/modules ([d] means folder, [f] means file)

[d] hooks_tutorial
     [d] config
          [f] config.php
     [f]  MyHooks.php

config.php

add the following code:

<?php

$GLOBALS['TL_HOOKS']['processFormData'][] = array('MyHooks', 'myProcessFormData');

MyHooks.php


add the following code:


<?php

class MyHooks extends Controller {
public function myProcessFormData($arrPost, $arrForm, $arrFiles) {
// your code here
}
}

According to the Hooks Documentation:



  • $arrPost is an array containing the data submitted by the user through the form

  • $arrForm is an array containing the form configuration as defined through the Backend Form Generator

  • $arrFiles is an array containing the files submitted by the user through the form (if any)

No comments:

Post a Comment