• A new version of Full Calendar is now available.

    See the details here

Approve form before PDF generation

sunnyjey

Active Member
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.
 
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:
$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:
return $formModel->formData['yourtable___status_changed_raw'] == '1';

Obviously change all the element names to match yours, but keep the _raw suffix.

-- hugh
 
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,
status.png


join database field EDITOR
editor.png

and calc Hidden status_changed field.

status_change.png

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

php_approval.png
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.

email.png

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?
 
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
 
My Bad. I misinterpreted.

status_changed is no calc element, it's set by the php plugin
Use a field element.
status-2.png



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

php_editor.png



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

Changed this code to '1'
Code:
return $formModel->formData['yourtable___status_changed_raw'] == '1';


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



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

Members online

No members online now.
Back
Top