Triggered by the enhancer before displaying the form to the user.
Allows to modify the $fields and the $layout. The $item (Model_Form instance) and $enhancer_args (label_position, etc.) variables are read-only.
Parameters: |
|
---|
<?php
Event::register_function('noviusos_form::rendering', function(array &$args)
{
$fields =& $args['fields'];
$layout =& $args['layout'];
$form = $args['item']; // Instance of Nos\Form\Model_Form
$enhancer_args = $args['enhancer_args'];
// This is an exemple of what $layout contains
$layout = 'noviusos_form::foundation';
foreach ($fields as &$field) {
// This is an example of what $field contains
$field = array(
'label' => array(
'callback' => array('Form', 'label'),
'args' => array('Label:', 'technical_id', array(
'for' => 'field_technical_id',
)),
),
'field' => array(
'callback' => array('Form', 'input'),
'args' => array('field_name', 'field_value', array(
'id' => 'field_technical_id',
'class' => 'field_technical_css',
'title' => 'Label:',
'placeholder' => 'Label:',
'required' => 'required',
)),
),
'instructions' => array(
'callback' => 'html_tag',
'args' => array('p', array('class' => 'instructions'), 'Instructions for the user'),
),
'new_row' => true,
'new_page' => true,
'width' => 4,
'item' => $item, // Instance of Nos\Form\Model_Field
);
}
// ...
}
Same as noviusos_form::rendering, but only triggered for a form with the specified <virtual_name>.
Warning
This function must return an array containing the detected validation errors.
Additional data validation after submitting a form from the Form application.
Parameters: |
|
---|---|
Return array: | List of validation errors |
<?php
Event::register_function('noviusos_form::data_validation', function(&$data, $fields, $form) {
$errors = array();
// This will mark all fields as error
foreach ($data as $name => $value) {
$errors[$name] = '{{label}}: ‘{{value}}’ non valid.';
}
return $errors;
});
The messages can contain the {{label}} and {{value}} placeholders (they will be replaced appropriately).
Same as noviusos_form::data_validation, but only triggered for a form with the specified <virtual_name>.
Before saving the answer in the database
Parameters: |
|
---|---|
Return bool: | false to prevent saving the answer in the database |
<?php
Event::register_function('noviusos_form::before_submission', function(&$data, $form, $enhancer_args) {
// You can alter $data before saving them into the database
// Or you can return 'false' if you don't want the answer to be saved in the database
return false;
});
Same as noviusos_form::before_submission, but only triggered for a form with the specified <virtual_name>.
After the answer has been created (not saved in the DB yet)
Parameters: |
|
---|
<?php
Event::register('noviusos_form::after_submission', function($params) {
$answer = $params['answer'];
$enhancer_args = $params['enhancer_args'];
// ...
});
Same as noviusos_form::after_submission, but only triggered for a form with the specified <virtual_name>.