Joomla4/Fabrik4 PHP Validation setMessage() Call to undefined method error

hominid4

Member
Sorry, this may be posted somewhere and I'm not seeing it, and I may should be posting in the Joomla forum, but does does setMessage work in Joomla4/Fabrik4? I have a fresh Joomla4/Fabrik4 install and when I add setMessage to an element's PHP Validation within the 'PHP code' box I get the error:

Call to undefined method FabrikEvalClass_1baf7b4cb62ba87a939bf89186be194e::setMessage()

Such as just when doing the simple code below:
PHP:
$this->setMessage('Element error message');
return false;

I've tried all different ways and research but not having luck, and before I spent further time on it just wanted to make sure. I'm able to do enqueueMessage() just fine, but needing to change the element's direct error message to different error messages based on my PHP query code.

Thanks!

J! 4.3.3
Fabrik 4 Delta (2023-06-01)
 
Last edited:
Can you try this please. I have not tested it but it should work.

Change plugins/validation_rul/php/php.php line 106 from
Code:
        $return = Php::Eval(['code' => $phpCode, 'vars' => ['data' => $data, 'formData' => $formData]]);
to this:
Code:
        $return = Php::Eval(['code' => $phpCode, 'vars' => ['data' => $data, 'formData' => $formData], 'thisVars'=> ['setMessage'=> $this->setMessage]]);

See if that solves it for you.
 
No, it doesn't. setMessage is no property but a method.

In plugins/validation_rule/php/php.php line 106
$return = Php::Eval(['code' => $phpCode, 'vars' => ['thisValidation' => $this, 'data' => $data, 'formData' => $formData]]);

and
$thisValidation->setMessage('xyz');

in the validation php code should do.
 
Thanks a bunch. I've replaced that line but I am still receiving that same error. I've restarted the server just in case.

Regarding that line, my original line before I changed it is on line 113 and is:
PHP:
$return = Php::Eval(['code' => $phpCode, 'vars'=>['data'=>$data]]);

I do see the $formData was added on 2023-06-05 but my file is from the 2023-06-01 4.0 Delta download. Just wanted to mention that in case it helps.

Thanks again, please let me know if I need to make further adjustments to the file.
 
I've replaced that line
With which code, mine or @achartier's?
If you take my code you must also change your code in your php validation to $thisValidation->setMessage('xyz');

With or without 'formData' => $formData doesn't matter as long as you don't use $formData in your php code.
 
Ah, sorry troester, I had pulled up and left up this message thread after achartier replied and didn't see your reply, and my reply referenced his. Sorry about that. I used your solution and it worked perfectly. Thanks!
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top