The beforestore Event, accessible with the field code "BeforeStore", allow you to change the content of each field of a form, just before they will be stored in database.
For that, you just have to put a field code "Beforestore" in your form and write the php code you need. By the setting of the code field, you can write the php code at two places :
- Mode "Free" => write directly the code in the textarea of the field code
- Mode "Files" => add the path to a file which contain your code
In the BeforeStore event, you can access 2 variables :
- $fields => the array of each form fields
- $config['storages'] => tha array of database tables
To modify the value of a field, you have to change it's value in the 2 places above :
1 - the field itself :
$fields['my_field']->value = 'my_new_value';
2 - In the array "storages"
$name = $fields['my_field']->storage_field; $table = $fields['my_field']->storage_table; $config['storages'][$table][$name] = 'my_new_value';