Calling error short code from PHP

Display error messages from PHP code in ChronoForms.

Overview

The issue occurs when using PHP logic blocks to output CF error shortcodes, which can cause formatting problems and prevent the messages from appearing correctly within the form.
Use a Custom Code block instead of a PHP block and employ the Joomla enqueueMessage method to display the error. This ensures messages are properly generated and displayed within the Joomla system, though they will appear in the standard Joomla message area rather than directly within the CF form.

Answered
ChronoForms v6
Ni NickOg 12 Apr, 2019
I have been able to use this succesfully in the past (from a validation procedure)
  if (!isset($thisData['conveners'])) {
$isDataValid = 'NO';
?>
{error:You must include at least one convener}
<?php
} else {
Now the text appears on return to my form but this is the result
Calling error short code from PHP image 1

The 'just testing' message comes from a custom code control.


Ways round it but it was working.

Nick
he healyhatman 12 Apr, 2019
if(empty($this->data("fieldname"))

And this is in a Custom Code block, right?
Ni NickOg 12 Apr, 2019
isset seems to detect the error but empty makes more sense.

function is called from a php logic block so:
Calling error short code from PHP image 2

Nick
he healyhatman 12 Apr, 2019
Yes but the block you're having trouble with, is it in a PHP block or a Custom Code block?

Also you can just do it like this
JFactory::getApplication()->enqueueMessage("Message", "type");

https://docs.joomla.org/Display_error_messages_and_notices
Ni NickOg 12 Apr, 2019
a php block. I will swap to a custom code block shortly and try that first. I can use the PHP approach if not.

Nick
Ni NickOg 12 Apr, 2019
Answer
Using a custom code block partially fixed it.
<?php
$this->set('validateCourseDataValues',validateCourseDataValuesV6($this->data,$this->get('read_data1.mdlTermInfo')));
?>
The messages appeared correctly but while validateCourseDataValues is set within the php code {var:validateCourseDataValues} is not available outside that custom code. I could not use the return values in a event switch.

The enqueueMessage method works though the message appears in the PHP form rather than the chronoforms orm.

Nick

.
This topic is locked and no more replies can be posted.