Results 1 to 3 of 3

Thread: Conditional field

  1. #1
    User
    Join Date
    01-25-10.
    Location
    France
    Posts
    61

    Default 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
    Sharing and growing

  2. #2
    Experienced user
    Join Date
    01-12-10.
    Posts
    814

    Default 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
    }

  3. #3
    Experienced user
    Join Date
    08-21-09.
    Posts
    563

    Default 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
    Brian

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •