1. If you update to Joomla 3.8.10, please make sure that you either do a full GitHub update of Fabrik, or disable caching for your lists (in the Advanced settings) or turn off Joomla's System Cache setting. A change in Joomla's cache code in 3.8.10 required a fix in Fabrik, which will be rolled in to the next release, but is currently only available in GitHub.
    Dismiss Notice
  2. We will be performing an update of XenForo (the forum software use on this site) this afternoon, Fri 8/17/2018. The forums will be unavailable for a (hopefully!) short time.
    Dismiss Notice

Validation Plugins

Feb 25, 2018
Validation Plugins
  • Every element can be validated during input to ensure that the data being entered meets defined criteria e.g. required or integer or in a particular format (e.g. phone numbers).

    Validation is performed using Validation Plugins, each of which is described separately.


    Validation conditions(top)


    Most validation plugin's have a condition field. This expects to receive a PHP statement which returns true or false.
    If it returns true then the validation is run
    If it returns false then the validation is ignored.

    Sometime it is desirable that the validation is only run, when the element on which it resides, is editable by the current user. This prevents a lock, when the element would not validate and the user can not edit this element. It could be done by the following condition:
    PHP:

    return $this->elementModel->canUse();
     
    which returns true if the current user can edit the element.

    Validations can use placeholders, so a valid condition statement is:

    PHP:

    return '{table___element}' === '1';
     
    For multiple conditions you can use the following format

    PHP:

    or condition
    return '{table___element}' == 2 || '{table___element}' == 1;
    and condition
    return '{table___element}' == 2 && '{table___element}' == 1;
     
    To only run a condition if the user has new/edit access for that element:

    PHP:

    return $this->elementModel->canUse();
     
    Since 21 Sept 2015, when the element which is being validated is in a repeat group, '{table___element}' will refer to the repeat group's data.

    Preventing validation based on a condition (top)

    Example:
    Element A has three options "Foo", "Bar", "Dog"
    Element B is conditionally hidden and has a Validation of "notempty"
    If "Foo" or "Bar" is selected then Element B shows up.
    If "Dog" is selected Element B is hidden but still requires validation!
    To prevent the validation of radio element B if value of radio element A is "Dog" - put the following code into the condition textarea of element B.
    PHP:

    if ('{table___element_a}' == "Dog")
    {
    return false;
    }
    else
    {
    return true;
    }
     

    Translating Validation Error Messages (top)


    Validation error messages are parsed through Joomla's JText function meaning you can provide translations for you error messages.


    • First edit an element and create a validation rule e.g. a not empty rule
    • Enter 'COM_FABRIK_CUSTOM_NOT_EMPTY' as the 'Error message'
    • Save the element
    • Go to Extensions -> language manager -> overrides
    • From the language drop down on the right hand side, select the language for which you want to provide a translation (e.g. select 'Englsh (United Kingdon - SIte)')
    • Press the 'new' button
    • Enter 'COM_FABRIK_CUSTOM_NOT_EMPTY' as the 'Language constant. This should match your validation's error message
    • Provide a translation in the 'Text' textarea, e.g 'Please enter something'
    • Save the entry

    Validation icons(top)

    Validation icons can be defined in the plugin settings "Options" (Extensions/Plugins)
    Insert your icon name, e.g. star or envelope