1. NOTICE: If you are using Fabrik and update to Joomla 3.10, you will need to update to Fabrik 3.10. And, if you are using Fabrik, do not upgrade to Joomla 4, we do not have a supported version ready for release. More information on a release date coming soon. Also, please note that Fabrik 3.10 will not install on any Joomla sites less than 3.8.
    Dismiss Notice

Need help with PHP/eval

Discussion in 'Community' started by barraclm, Oct 18, 2021.

  1. barraclm

    barraclm New Member

    Level: Community
    I have a list, 'Titles', that has 3 elements (excluding ID and timestamp). Two of the elements (title and title_article) have been loaded via a CSV import. They show up fine in List>Show Data for the list and they are good in the underlying database table (ds_titles).

    The 3rd element (full_title) is supposed to be a combination of the title and title_article elements, such that if there is a value for title_article it is appended to the title, and saved in the full_title element. To do this I have the element full_title defined as a field and have the following PHP code in the default section of the element definition (with eval set to YES).

    $full = {ds_titles___title};
    $article = {ds_titles___title_article};
    if (!is_null($article)) $full = $full . ", " . $article;
    return $full;

    At the very least I would expect List>Show Data to contain the title element (based on lines 1 & 4). However, List>Show Data has the Full Title column, but it is empty. It does not matter whether I have the placeholders raw (as above) or have them surrounded by ' or ". The result is the same. In the underlying database table, all the values are shown as NULL.

    I would be most grateful if someone could help me understand what I am doing wrong.

    Michael Barraclough
  2. juuser

    juuser Well-Known Member

    Level: Community
    "Eval default" is considered only when adding new records. In your case you need calc element with the same code you have above.

    If you want the field to be searchable/orderable, you need to set "Only calc on save" to "Yes" in calc element settings. But in that case you need to open and save every existing record, so the value would be written to database. Or with larger amount of rows you could do a update query e.g. in PhpMyadmin.

    With "Only calc on save" set to "No", values are calculated "on the fly" and are only displayed, not written in database.
  3. barraclm

    barraclm New Member

    Level: Community
    Thank you.
  4. troester

    troester Well-Known Member Staff Member

    Level: Community
    If you are using Fabrik placeholders in php you must quote them.
    $full = '{ds_titles___title}';

Share This Page