Creating a Validation routine
As part of our ongoing effort to modernise and enhance the functionality of Jadu Central, in Jadu Central 3 we have implemented significant improvements to the validation routines and form validation mechanisms.
In this release, we have made Predefined Validation Routines extensible, enabling developers to customise and extend the validation logic according to their specific requirements.
Instructions on creating a new Predefined Validation routine
To add a new Validation routine, create a class which implements Jadu\XFormsPro\Form\PredefinedValidationRoutines\PredefinedValidationRoutineInterface
:
<?php
namespace Jadu\Custom\CustomXFormsProBundle\PredefinedValidationRoutines;
use Jadu\XFormsPro\Form\PredefinedValidationRoutines\PredefinedValidationRoutineInterface;
class CustomValidationRoutine implements PredefinedValidationRoutineInterface
{
public function execute(string $input): bool
{
// check the provided input string against custom validation constraints
// and return a boolean value indicating its validity
if ($input === 'Amazing') {
return true;
}
return false;
}
}
Register it as a service in services.yml
:
custom_xfp.predefined_validation_routine.custom:
class: Jadu\Custom\CustomXFormsProBundle\PredefinedValidationRoutines\CustomValidationRoutine
tags:
- { name: xfp.predefined_validation_routine, label: 'Custom Validation' }
- { name: xfp.predefined_validation_routine, method: 'validate' }
Create a migration which adds the new validation routine to table JaduXFormsFormValidation
; ensure title
and method
match label
and method
in your service definition:
INSERT INTO
`JaduXFormsFormValidation` (`title`, `type`, `method`, `regex`)
VALUES
('Custom Validation','predefinedvalidationroutine','validate','');