Input processors are a convenient way to pre-process, validate, and post-process data submitted by FormJinn forms. For the most part the default set of processors is comprised of validation processors. This shouldn't be much of an issue since pre-processing and post-processing are often highly custom and so one processor type, the custom processor, enables the developer to do anything they please with the data, including modification of other fields and the form itself. This can be handy if such cases as having 3 select widgets for specifying a date, but where you wish to work with a single value. You can assign a custom pre-processor to combine the disparate portions of the date into a single value, which can then be assigned to a field of type hidden for further validation or post-processing.
There are three types of processors that can be applied to
a FormJinn field. This is done by setting the value of the preProcess, validation, or
postProcess data fields of the FormJinn form
field by using its setData() method. The value
for each of these fields should be an array of arrays. Each array in the vlue
constitutes a configuration for an input processor. For example the following
demonstrates setting up a validation for a mandatory email address field:
$formJinn = $this->getService( 'formJinn' ); $aForm = $formJinn->do->createForm( 'exampleForm' );
$emailField = $aForm->do->createField( 'email', 'input' ); $emailField->do->setData ( 'validation', array ( array ( 'type' => 'mandatory', 'errorMessage' => 'You must fill this field.', ), array ( 'type' => 'email', 'errorMessage' => 'That email address is invalid.', ), array ( 'type' => 'regex', 'reverseLogic' => true, 'expression' => '@spamail\.', 'errorMessage' => 'Spamail addresses are not permitted.', ), ) );
spamail address. The first one of these that fails ends the
entire validation process. While this could have been done in the pre-process
or post-process stage, it is better to keep validation like this in the
validation stage. The reason being that by the time you reach the post-process
stage and a processor is executed (often a custom processor for committing
data to a database) then you are guaranteed the form's data has been properly
validated (notwithstanding developer error).
You can view detailed information about each of the FormJinn input processors types by selecting the appropriate link from the left navigation.