contao/import — Issue #3182: Add new hook 'storeFormData'
Author: DyaGa
Created: 2011-11-29 21:02:26+00:00
State: open
Labels: Accepted, Feature, frontend

I would like you to add new hook 'storeFormData'.
This hook will run before saving Form data to database in `processFormData` method (if such setting exists for Form).

Often for saving some data in Contao tables we have to also include in Form hidden fields (ex: `pid`, `tstamp`, `published` etc.).
We could generate this values in this hook.

So, here is proposed code for this hook (insert it at line:423 (http://api.contao.org/__filesource/fsource_Controller__modulesfrontendForm.php.html#a423)):

```
// HOOK: store form data callback
if (isset($GLOBALS['TL_HOOKS']['storeFormData']) && is_array($GLOBALS['TL_HOOKS']['storeFormData']))
{
foreach ($GLOBALS['TL_HOOKS']['storeFormData'] as $callback)
{
$this->import($callback[0]);
$this->$callback[0]->$callback[1]($arrSet);
}
}
```

This hook should be invoked as:

```
public function storeFormData(&$arrSet)
{
$arrSet['dateAdded'] = $arrSet['tstamp'];
}
```

Where `$arrSet` is a pointer to array with form data.
I don't know whether to effectively use this code... Maybe the function should return array?

--- _Originally created on June 20th, 2011, at 07:07pm (ID 3182)_