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.
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;
}
***