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

Form Plugin Whitescreens unless return false

pastvne

Bruce Decker
Hi
I have the following code in a php form plug-in using (onBeforeProcess) event


require_once(COM_FABRIK_BASE.DS.'bpi_edoc_scripts'.DS.'bpi_edoc_get_db_object.php');

$bpi_status = '{bpi_edoc_subscriptions___status}';


if ($bpi_status == 'approved') {
$hostUpdate = '{bpi_edoc_subscriptions___host_update}';
if ($hostUpdate == '') {
$bpi_timeDate = date('Y-m-d H:i:s');
$formModel->updateFormData('bpi_edoc_subscriptions___host_update_raw', $bpi_timeDate);
/*run query to determine if we have any documents already in database. If so
then, ignore otherwise send XML to notifications directory
*/

$bpi_select = "SELECT `bpi_edoc_document_control`.`id` FROM `bpi_edoc_document_control`";
$bpi_where = "WHERE `bpi_edoc_document_control`.`division_code` = '{bpi_edoc_subscriptions___division_code}' ";
$bpi_where .= "AND `bpi_edoc_document_control`.`cust_id` = '{bpi_edoc_subscriptions___customer_id}' ";
$bpi_where .= "AND `bpi_edoc_document_control`.`doc_type` = '{bpi_edoc_subscriptions___document_type}'";
$bpi_limit = "LIMIT 1";
$query = $bpi_select . ' ' . $bpi_where . ' ' . $bpi_limit;

$db->setQuery();
$bpi_results = $db->loadObjectList();

if ($bpi_results == '') {
$bpi_edoc_notifyPath = $_SERVER['DOCUMENT_ROOT'] . DS . 'bpi_edoc_exchange' . DS . 'bpi_edoc_notifications';

$bpiXML = new SimpleXMLElement("<notification></notification>");
$bpiNotification = $bpiXML->addChild('timeDate', $bpi_timeDate);
$bpiNotification = $bpiXML->addChild('type', 'subscription');
$bpiNotification = $bpiXML->addChild('event', 'approval');
$bpiNotification = $bpiXML->addChild('subscriberId', '{bpi_edoc_subscriptions___subscriber_id}');
$bpiNotification = $bpiXML->addChild('divisionCode', '{bpi_edoc_subscriptions___division_code}');
$bpiNotification = $bpiXML->addChild('documentType', '{bpi_edoc_subscriptions___document_type}');
$bpiNotification = $bpiXML->addChild('customerId', '{bpi_edoc_subscriptions___customer_id}');
$bpiNotification = $bpiXML->addChild('myCompanyName', '{bpi_edoc_subscriptions___my_company_name}');
$bpiNotification = $bpiXML->addChild('reachMeAt', '{bpi_edoc_subscriptions___where_can_we_reach_you}');
$bpiNotification = $bpiXML->addChild('customerNotes', '{bpi_edoc_subscriptions___customer_notes}');
$bpiNotification = $bpiXML->addChild('approvedByUserId', '{$my->id}');
$bpiNotification = $bpiXML->addChild('approvedByUserName', '{$my->username}');
$bpiNotification = $bpiXML->addChild('approvedByName', '{$my->name}');
$bpiDom = new DOMDocument("1.0");
$bpiDom->preserveWhiteSpace = false;
$bpiDom->formatOutput = true;
$bpiDom->loadXML($bpiXML->asXML());

$bpi_fileName = $bpi_edoc_notifyPath . DS . 'subscriptionApprove_{bpi_edoc_subscriptions___division_code}_{bpi_edoc_subscriptions___customer_id}_{bpi_edoc_subscriptions___document_type}.xml';
$bpi_putStatus = file_put_contents($bpi_fileName, $bpiDom->saveXML());

}
}
}
return false;

Having the last line (return false;) is the only way I've been able to get Fabrik to return to the list after submit. If I do any of the following, the php code fires but I'm left on a whitescreen and fabrik never redisplays the list:

a) leave off return entirely
b) return
c) return true

While 'return false' is allowing the code to execute and causes fabrik to return to the list view, it does not save the changes made to the form into the database.

Can someone help me understand what I've done wrong?
I may move some of the code to an after submit but for right now, I'd like to understand what I'm doing to cause the onBeforeProcess event to whitescreen.

Thanks,
Bruce Decker
 
I had another PHP plug-in also on the form to process after submit. I took the code there and placed it into the OnBeforeProcess plug-in and it works without any return. So, there is some collision between plug-ins. For my purposes, I would have liked to have used two separate plug-ins but I can make things work using one OnBeforeProcess plug-in so I'll just go with that for now. However, if there is advice to be had, I'm still all ears.
 
Returning false in an "onBefore" plugin is stopping the submission.
So I suspect the whitescreen is not coming from your php plugin but happening afterwards.

Whitescreen: Set Joomla error reporting to maximum to get an error message.
What happens if you disable this plugin?
 
Thanks Troester. I will update the object name in my code.
I resolved the issue by disabling the OnAfterProcess event and moving the code in that plug-in to my OnBeforeProcess event. When I did that, all was fine. So, perhaps something I was doing in the code had an impact on the handler for OnAfterProcess. Perhaps I did manipulate something in Fabrik inadvertently. Thanks for the tip. I'll report my results.
-BD
 
I just moved the instances of $db to $bpiDb across all scripts and restested but the same result. The script in onBeforeProcess runs but it does not appear to make it past that point. Later this week and experiment with increasing Joomla debugging and looking at that trace. For now, I just moved the instructions in onAfterProces to onBeforeProcess so that I have only one plug-in on this form. That appears to work for me.
 
Troester. The change from $db didn't solve the issue but it did get me thinking. Through debugging I was able to see that a failure was happening if I reference the database object. I was getting the database object from a require_once include in both plug-ins. I changed that to call the JFACTORY class instead and then both plug-ins worked. The issue seems to be the use of require to get a handle to the Joomla database within a required include in a plug-in.

I now have both plug-ins working.

Thanks for putting me on the right track!
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top