Calc element not storing to DB

Status
Not open for further replies.

VOI

Member
Hi,
i have a problem using the calc element. I want to fetch a value from the DB, display it and save it.
The problem is that the value is displayed correctly, but not stored to the DB.
Here is my calc element code, maybe someone can tell me what i did wrong:
PHP:
$ddval = JRequest::getVar('timerec___project_title');
 
$db = FabrikWorker::getDbo();
 
$query = "SELECT `project_number` FROM `projects` WHERE `project_title` = '$ddval'";
$db->setQuery($query);
$views = $db->loadResult();
 
return $views;

The ajax observed field is timerec___project_title.

Thanks for your help.
 
If the data is displayed in the list correctly, then your calc works as expected. But the calculated value is shown "on the fly". In order to store it, you have to edit/save any existing record. For new records, the data will be stored when the form is submitted.
 
Well, i forgot to mention that i already tried that, it wont save after form submission either
 
OK. Does your title contains any single or double quotes?
You can try to use
Code:
return addslashes( $views );
to see if that helps.
 
No that did not help.
The timerec_project_title field is a databasejoin rendered as dropdown. The problem only appears if i fetch the value via SQL, if i fix the value of $views it gets stored to the DB normally.
Any other suggestions?
 
The display result is : string(3) "123" - But still no saving to the DB. Additionally i get a NULL displayed outside of the form.
 
can you post a screen shot of you calc element settings and a link to the form?
 
Although I don't see how it can be related to the issue, you should clear the "Ajax fields" box as it is only useful if you need to observe other fields than the one(s) that are in the calculation.
In any case, if you want to leave it there, you have to remove the {} as it is the element's name that is required, not its value through the placehoder.
 
Well, when clearing the "ajax fields" box it stops working. But it does work with or without brackets, i just used the brackets because the tooltip said so.
Nevertheless the initial problem isnt fixed by changing the ajax fields box.
 
have you tried with 'Only Calc on Save' set to 'yes'
Currently, with it set to 'no' the calculation is run when the list is rendered so if there is no request variable project_time then the query will result in displaying most likely an empty string.

So, set 'Only Calc on Save' to 'yes', edit and save a record, and see if that works.

-Rob
 
yes, i tried that before. tried it again now, but did not change anything.
i noticed that if i fill in a value to the DB manually, it wont show either. maybe this helps you finding the error.
 
sorry no idea! So you are saying you fill in the field value in phpmyadmin, have the element set to only calc on save, and still nothing shows in the list view?
 
Yes, i tried it again now: I filled in a testvalue in phpmyadmin and then opened list view - nothing shows. When i then open detail view of a record, the testvalue is displayed correctly. But after saving the form, the testvalue is replaced with a NULL. Somehow there seems to be a mismatch between what is displayed in details view and what is stored to the DB.
I just dont understand if its a problem with my code or my configuration, or if this functionality isnt even supported by Fabrik. Maybe someone could try to reproduce this behaviour?
 
have you tried doing simply:

PHP:
return 1;

this works for me.

if that isnt working then there is something really odd on your site.
If it works then its something in your calculation
 
Ok, tried that now. The '1' is stored to the database as expected and is displayed in details view, but not in list view, which is weird i think.
Something seems to be wrong with storing the value of the SQL statement to the PHP Variable, maybe there is another way to do this?
 
still can't replicate this. when you say it doesnt show in the list view, are you saying the column is not shown, or that that column is shown but the data is blank?
Are you using the latest github code?
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top