1. NOTICE: If you are using Fabrik and update to Joomla 3.10, you will need to update to Fabrik 3.10. And, if you are using Fabrik, do not upgrade to Joomla 4, we do not have a supported version ready for release. More information on a release date coming soon. Also, please note that Fabrik 3.10 will not install on any Joomla sites less than 3.8.
    Dismiss Notice

Approve form before PDF generation

Discussion in 'Professional Support' started by sunnyjey, Sep 27, 2017.

  1. sunnyjey

    sunnyjey Active Member

    Level: Community
    I have form A where Registered Members submit required data.

    After submission of Primary data, it should send Email to the predefined Email address (EDITOR Group).

    The form should be published only when approved by the Members from Editor Joomla Group. I guess, I have to create a radiobutton field with option like 1. Approved 2. Pending Approve 3. Not Approved.

    After approval by the EDITOR, it should append the NAME of Editor who has approved the Form data in the LIST and DETAIL View. How do I fetch Name of Editor and Append his Name to the Primary Form ?

    Then it should send another EMAIL containing PDF of the Detail data.

    Please guide me how to do it.

    Thank you.
  2. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    It wouldn't be entirely trivial, as you'd need to detect when the status has changed, which means comparing the original data to the modified data being submitted.

    So it'd need a PHP submission script, set to run on 'edit', which does something like this ...

    Assuming you have a 'status' element with value of '2' for Approved, and an 'editor' element (a join to your #__users table, value 'id', label 'username' (or whatever)), and a hidden field element, 'status_changed'.

    Code (Text):

    $origData = $formModel->getOrigData();
    $origData = FArrayHelper::getValue($origData, 0, new stdClass);
    $origStatus = $origData->yourtable___status_raw;
    $origStatus = is_array($origStatus) ? $origStatus[0] : $origStatus;

    $newStatus = $formModel->formData['yourtable___status_raw'];
    $newStatus = is_array($newStatus) ? $newStatus[0] : $newStatus;

    if (($newStatus != $origStatus) && $newStatus == '2') {
      $formModel->updateFormData('yourtable___editor', JFactory::getUser()->get('id'), true);
      $formModel->updateFormData('yourtable___status_changed', '1', true);
    else {
      $formModel->updateFormData('yourtable___status_changed', '0', true);
    That will set the 'editor' element to logged in user when the status is changed from anything else to '2'.

    Then for the email, have a "Condition" of ...

    Code (Text):

    return $formModel->formData['yourtable___status_changed_raw'] == '1';
    Obviously change all the element names to match yours, but keep the _raw suffix.

    -- hugh
  3. sunnyjey

    sunnyjey Active Member

    Level: Community
    Thank you. I have been trying to work this code since last 3-4 hours. But no luck so far. Somehow the email is not getting fired even after status change.

    As per your advised,

    I have created Status Radiobutton element,

    join database field EDITOR

    and calc Hidden status_changed field.


    I also created Php plugin and entered data and changed the name of elements.

    Tried few options of Script process - onLoad/AfterLoad. But didn't work. What should be correct option here?

    Finally, created Email plugin and placed the condition. Here also tried options of 1 and 2. But didn't work.


    There is one more problem, I have Digital signature Element where user signs in Form. This is reflected on the generated PDF. But, after Edit by the second user (Editor), though the Digital signature of Primary user is displayed on submitted detail page, but it gets disappear on PDF Report after Saving form by the Editor. I guess this is something related to the DomPDF security.

    How do I disable this security, so that the digital signature of primary user is displayed in Final PDF report even after Edit by the Editor?
  4. troester

    troester Well-Known Member Staff Member

    Level: Community
    status_changed is no calc element, it's set by the php plugin
    Use a field element.

    The php plugin must run "onBeforeStore", not "onLoad".

    The email condition is ...status_changed... == '1'; //tatus_changed is 1 if the status has changed and is 2
  5. sunnyjey

    sunnyjey Active Member

    Level: Community
    My Bad. I misinterpreted.



    Changed this code to '1'
    Code (Text):

    return $formModel->formData['yourtable___status_changed_raw'] == '1';

    Tried to change default option from 0 to 1 value in following Element.

    Still email is not getting fired. I have verified entered email address in TO of Email Plugin and also checked Spam folder, in case.

    The good thing is that, the SIGNATURE has come back. I can see signature in PDF document after edit also.

    So what is wrong now..
  6. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    Really the only way I can help at this point is to get on your server and do it for you. I don't usualy do hands on coding as part of subscription support, but hopefully this will be a quick one.

    Is this on your 'canpath' site? Which form?

    -- hugh
    sunnyjey likes this.
  7. sunnyjey

    sunnyjey Active Member

    Level: Community
  8. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    Should be working now. Couple of things ...

    My bad on this one, the condition is either ...

    return $formModel->formData['status_changed_raw'] == '1';

    ... (without the tablename___ prefix) ... or ...

    ... or ...

    return '{yourtable___status_changed_raw}' == '1';

    ... (using placeholder) ... or ...

    return $data['yourtable___status_changed_raw'] == '1';

    ... with the prefix. I changed it to the latter.

    And you shouldn't set the "Email sent field". As the tooltip for that says, it won't send if that value is non-zero. The email sent field is used for the specific purpose of only sending the email one time. If it's 0, we send the mail and set the field to 1.

    -- hugh
    sunnyjey likes this.
  9. sunnyjey

    sunnyjey Active Member

    Level: Community
    I have no words to thank you.

    Yes, it is working as per my requirement.

    Thank you so much for taking time and doing this for me beyond your usual scope of work.
  10. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    You're welcome.

    -- hugh
    sunnyjey likes this.

Share This Page