-
Conditional field
Hello,
I am searching for a solution to show/hide (or validate input in a fiels text) if an special item is selected from a select menu.
The select menu and the the text field are on a same frontend form.
Some one has a way to solve this ?
Thanks a lot
-
Re: Conditional field
If you want that done without submitting the form, use javascript. Perhaps give the form an id to hook into. Contao comes with Mootools, that shuld make it easier to do it, though I never use it myself...
If you want to validate the input upon submitting and reporting back if the input is invalid, you can use the processFormData hook, described at http://www.contao.org/hooks.html
processFormData
The processFormData hook is triggered after a form has been submitted. It passes the form data array, the Data Container Array and the files array as arguments and does not expect a return value. It is available from version 2.4.4.
Code:
// config.php
$GLOBALS['TL_HOOKS']['processFormData'][] = array('MyClass', 'myProcessFormData');
// MyClass.php
public function myProcessFormData($arrPost, $arrForm, $arrFiles)
{
// Do something
}
-
Re: Conditional field
The only thing about the processFormData hook (I was just using it yesterday for something) is that it only fires AFTER the form is submitted, so it doesn't seem to be suitable for validation because you can't stop the submission.
There's a "validateFormField" hook instead for validating fields:
http://www.contao.org/hooks.html#validateFormField