1. "Fabrik 4" helpers needed!

    You are invited to join other community members active in coding, maintaining and improving Fabrik. Please visit https://fabrik.help for more information!
    Dismiss Notice

Form Plugin Whitescreens unless return false

Discussion in 'Standard Support' started by pastvne, Jul 1, 2017.

  1. pastvne

    pastvne Bruce Decker

    Level: Community
    I have the following code in a php form plug-in using (onBeforeProcess) event


    $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;

    $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;

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

    Bruce Decker
  2. pastvne

    pastvne Bruce Decker

    Level: Community
    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.
  3. troester

    troester Well-Known Member Staff Member

    Level: Community
    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?
  4. troester

    troester Well-Known Member Staff Member

    Level: Community
  5. pastvne

    pastvne Bruce Decker

    Level: Community
    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.
  6. pastvne

    pastvne Bruce Decker

    Level: Community
    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.
  7. pastvne

    pastvne Bruce Decker

    Level: Community
    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!
  8. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    Yes, always grab the DB object inline where you need it, with a JFactory::getDBO().

    -- hugh

Share This Page