• 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.

Problem witch calc element on submit

Björn

New Member
Hey there,
I trying to save the joomla user id with calc element to the database.
This is the script I use and it works fine.

$host_id = $data["events___host_id"];
if(empty($host_id)){
$host_id ={$my->id}*1;
}
return $host_id;

But if an admin try to edit the form and click on submitbutton, the form save the id of the admin instead the user-id which was saved before.
Do you have an idea how to fix it?
 
No idea how to fix it. But if you want to convert text to integer, then rather than multiplying by 1 the correct syntax would be:
Code:
$host_id = (int) {$my->id};
 
Thanks for the hint. I changed that. Unfortunately that does not solve the problem.
Code:
$host_id = $data["events___host_id"];
if(empty($host_id)){
$host_id = (int) {$my->id};
}
return $host_id;
 
It seems $data["events___host_id"]; is always empty.
Where is it coming from?

What do you want to achieve?
Do you want to store the userid of the creator of the record (i.e., on add, no modification on edit)?
Use the "user" element.

Additionally:
In php you should always quote a placeholder to avoid breaking code if it's empty.
({$my->id} is never empty, so no problem here, but in general use '{...}' )
 
Thanks @troester - I was just about to mention the quoting thing. How about this code:
Code:
$host_id = '{events___host_id}';
if(empty($host_id)){
    $host_id = (int) '{$my->id}';
}
return $host_id;
 
The first time I open the form, the data variable is empty and the $ my-> id will be stored.
If I edit a foreign entry, the stored value is also loaded correctly with my script.
Only when submit the form, $ my-> id is saved again.

Anyway, I've tried that with the user element and it seems to work.
Many thanks for the answers. Sometimes it can be that easy.
 
Looks like you were trying to do exactly what the user element is there to do, so yes ... it should work. :)

And one of the benefits of using the user element is you get the option as to whether you want the id updated on edit or not.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top