• Fabrik4.5.3 for J!5.3.0 and J!4.2+is out

    You must update from Fabrik4.5.1 if you are running Joomla!5.3.0

    See Announcements

Element default examples

  • Views Views: 24,329
  • Last updated Last updated:

Navigation

      Access element (+)
      Birthday element
      Button element
      Calculation element
      Captcha element
      Checkbox element
      Colour Picker element
      Count element (+)
      Database join element
      Date element
      Digg element
      Display text element
      Dropdown element
      Facebook Like element
      Field element
      File Upload element
      Folder element
      Google Map element
      Image element
         Image databese join
      Internal id element
      IP element
      J!Date element
      Kaltura element
      Link element
      Notes element
      OpenStreetMap element
      Picklist element
      Radio Button element
      Rating element
      Sequence element
      Slider element
      Tags element
      Textarea element
      Thumbs element
      Time element
      Timer element
      Timestamp element
      Total element
      User element
      User group element
      Video element
      View level element
      YesNo element
      Youtube element
      Akismet validation
      Is Email validation
      Is Not validation
      Is Numeric validation
      Not empty validation
      PHP validation
      Rsa id
  • Many Elements have both a "default" option and an "eval" option.
    When you turn on "eval", the text entered in the "default" option is treated as PHP.
    The PHP expression is evaluated and the data 'returned' is used as the element's default value.

    PHP:
    return 'a string';

    Using placeholders....
    PHP:
    return '{tablename___elementname}';

    Get a filter value
    PHP:
    return FabrikHelperElement::filterValue(81); //81 is the id of the filter element

    Insert a URL parameter (e.g. to set the default of a non-writable element, which can't be set for security reasons directly via URL)
    PHP:
    $myInput = JFactory::getApplication()->input;
    $myParam = $myInput->get('urlparam','');
    return $myParam;

    *** The above worked great before Joomla 4. I use the following now and it seems to work as expected.
    PHP:
    $myInput = \Joomla\CMS\Factory::getApplication()->getInput();
    $myParam = $myInput->get('urlparam', '');
    return $myParam;
    ***

    *** If your element default value happens to depend on a url parameter (similar to the above), but the default value itself isn't necessarily the value of the url parameter, you can create a conditional statement using the url parameter value. In this post (Assign default element), troester noted that you can use url Placeholders like {formid}, {rowid} or {myParam} (similar to using {tablename___elementname}), but included a very important comment: "In general you should use Joomla or Fabrik functions to get input parameters etc.". This is to ensure that the value in the url is "scrubbed" before being included as an element's value in a form- mitigating the risk of "bad actors" possibly inserting harmful code.
    So don't do this:
    PHP:
    if($_GET["myParam"] == "123"){
    $myFormDependentValue = "some value";
    return $myFormDependentValue;
    }

    Instead, you can either follow the advice above and use $myParam to create your condition or simply use the Fabrik placeholder of the url parameter:
    PHP:
    if({myParam} == "123"){
    $myFormDependentValue = "some value";
    return $myFormDependentValue;
    }
    ***
Back
Top