Triggering events in form php plugin

deant

Active Member
Hello,

I have a quite complicated form where the user enters data. Many things happen before saving and after saving the form. I use several form php plugin which are hooked on different time.

I have difficults with the last thing on the form (php plugin set onAfterProcess) which is creating a pdf report and save file on the server. The pdf is then transferred to the company document system.

The procedure is as follows:
1. Creating and saving pdf - works
2. Receiving bearer token - works
3. Upload pdf to document system - works
4. Get response from document system server - works
5. Save response data to db (same form row id)
6. Open new tab with link we received in response - not works

Open new tab in php plugin is mission imposible so I try to work around. I was create js fabrik.form.submit.end which call ajax to get link and open new tab.
Sometimes I get link and open new tab but in most casses not. I assume the problem is time and triggering events. To create and save two(2) pdf pages takes 2-3 seconds then upload to document system also takes 2-3 seconds. BTW in js code I set timeout 2-3 sec befor calling ajax.

Will be better if I set to onBeforeProcess? ...or any other solution?

Thanks
 
Maybe a workaround:
Create a system message with the link, something like
Code:
$m= "<a target='_blank' href='your-link'>some text</a>";
$myapp = JFactory::getApplication();
$myapp->enqueueMessage($m);
 
I tested...I get a link in ACL message. It is allmost the same if I display link in table row.

The more I think about this I see no other option that the user has to manually click on the link.

I hoped to have a full automatic solution without additional click.
 
It is allmost the same if I display link in table row
Yes, it's just an "eyecatcher" after the redirect where you could add additional text or instructions or display it as warning etc.
 
This should open a new tab automatically
  • add a redirect plugin to your form with a parameter e.g. &mylink=something (the link or the rowid)
  • in the list you are redirecting to add a php_events plugin and "onLoadData" do something like
    Code:
    $myapp = JFactory::getApplication();
    $mylink = $myapp->input->get('mylink','');
    if (!empty($mylink) ) {
    //some code to create your link
    echo '<script type="text/javascript" language="javascript">
      window.open("your link", "_blank");
    </script>';
 
This probably works if php pluhin is setup on onBeforProcess and data can be storeed in fabrik field...onAfterProcess data can be stored only in db.

I will try... I'll set my php on onBeforProcess.

In a day or two I will let you know how it works. Have a lot of code to rearange.

Thx for now.
 
onAfterProcess data can be stored only in db
This is correct, but what is the problem to put the data directly into DB? You know the rowid and can do an UPDATE ...
 
This should open a new tab automatically
  • add a redirect plugin to your form with a parameter e.g. &mylink=something (the link or the rowid)
  • in the list you are redirecting to add a php_events plugin and "onLoadData" do something like
Just for feedback...your solution is working very well except your code. Redirect plugin passing my_link in url as query string so I change firsf part of your code to:

PHP:
$url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . ": //$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$query_str = parse_url($url, PHP_URL_QUERY);
parse_str($query_str, $output);
$my_link = $output['my_link'];

if (!empty($my_link)){
echo '<script type="text/javascript" language="javascript">
  window.open("'.$my_link.'", "_blank");
</script>'
;
}

Just in case if someone found it useful.

THX
 
Last edited:
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top