Adding a filter to a form element

To add a filter to an element, you will need to open process.php and find the code that creates the element you want to add the filter to. It may already have a line below it that is calling addFilters(), in that case just add the name of the filter you want to add at the end of the array that is passed in. If the element had the following code.

1
$element->addFilter('trim');
$element->addFilter('trim');

You can just add another line below that adds the new filter. For example if you wanted to add the alphaNumeric filter also you can make the code:

1
2
$element->addFilter('trim');
$element->addFilter('alphaNumeric');
$element->addFilter('trim');
$element->addFilter('alphaNumeric');

You could also use the following code (notice the method name is addFilters not addFilter)

1
$element->addFilters(array('trim', 'alphaNumeric'));
$element->addFilters(array('trim', 'alphaNumeric'));

You can also instantiate the filter directly then add it to the element. Which may help with your own custom filters if you need to make any that you need to pass options to, for example.

1
2
$trimFilter = new Quform_Filter_Trim();
$element->addFilter($trimFilter);
$trimFilter = new Quform_Filter_Trim();
$element->addFilter($trimFilter);
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy