• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

Need help with PHP/eval

barraclm

New Member
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
 
"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.
 
Additionally:
If you are using Fabrik placeholders in php you must quote them.
$full = '{ds_titles___title}';
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top