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

Getting error from Calc Element on a new form entry

smart

Member
Hello again.

I have a calc element with this codes below. List views and individual form view shows the correct result for that calc element. But when the new entry (form) is created, this error shows up.
0 syntax error, unexpected ')'
I am searching through the forum but hasn't found the correction solution yet.
Any help would be appreciated. Thanks
PHP:
if (!empty('{book___btid_raw}')) {
  $myDb = FabrikWorker::getDbo(false, 2);
  $myQuery = $myDb->getQuery(true);
  $myQuery->select("tnamee")->from("teacher")->where("tid = ". {book___btid_raw});
  $myDb->setQuery($myQuery);
  return $myDb->loadResult();
}
return '';
 
I suspect it is the first line. PHP "empty" function is intended to take a variable name as the parameter not a string. I suspect that this works when the string contains a value, but not when the placeholder is empty.

Instead, why not try:
PHP:
if ('{book___btid_raw}' != '')
 
Thanks Sophist.
It didn't work. I tried several variation even using $formModel->getElementData and not working.
As far as I understand, during the form load, the dbjoin element raw value would be NULL or empty. If there is only "IF" statement checking the empty, there is no error. But if there are that 5 lines code, it produces the error.
I admit I am not expert in php as well as fabrik. Still learning.
 
Hi Sophist,
Thanks. I think I find the error. Single quotes are needed for the place holder.
I am double checking now.
PHP:
  $myQuery->select("tnamee")->from("teacher")->where("tid = ". {book___btid_raw});
should be
PHP:
  $myQuery->select("tnamee")->from("teacher")->where("tid = ". '{book___btid_raw}');
 
Yes - obvious now you mention it. You think that the code is not executed when the placeholder is empty, but the placeholders are actually substituted into the php source code, so without the quotes when the placeholder is empty the code that is evaluated is actually:
PHP:
$myQuery->select("tnamee")->from("teacher")->where("tid = " . );
And now you can see why there is an unexpected ")".
 
I'd also add a $db->quote() or (as this seems to be a numeric id) cast it to an int, in there as well, so you don't wind up with a similar issue in the query itself ...

$myQuery->select("tnamee")->from("teacher")->where("tid = ".$myDb->quote('{book___btid_raw}'));

... or ...

$myQuery->select("tnamee")->from("teacher")->where("tid = ". (int)'{book___btid_raw}');

... or even just put the placeholder within the where string ...

$myQuery->select("tnamee")->from("teacher")->where("tid = '{book___btid_raw}'");

Otherwise you would end up with a query like ...

WHERE tid =

... which would throw a MySQL error, rather than ...

WHERE tid = ''

... or ...

WHERE tid = 0

-- hugh
 
Thanks, Cheesegrits. Your advice will be very helpful for this and the future queries as well.
I appreciate it. :)
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top