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