Form php plugin return data onAfterProcess

ontarget

Active Member
I am using a fabrik php form plugin to generate my short url (using YOURL) - its working fine however i need to echo or return my data onafterProcess of the form submission and show it to the user.
The link is shortened then captured in my variable $data
  1. So user fills out the form
  2. Clicks Submit
  3. Short url is created by form php plugin onAfterProcess
  4. How can I display the short url $data to the user after submission as it is not a fabrik element?

I can't use getBottom or getEnd as the URL needs to be generated by the data entered in the form otherwise its duplicated
I tried the redirect plugin but 'submission message' wont accept php?

Appreciate any help on this . I will post my full solution as YOURLS is a great alternative to bitly
 
You can create a system message
$myapp = JFactory::getApplication();
$msg = whatever
$myapp->enqueueMessage($msg);
or
$myapp->enqueueMessage($msg,'type');//type = 'message' (default, green with bootstrap CSS), 'notice' (blue), 'warning' (yellow), 'error' (red)
 
Thanks for the feedback Troester - I tried adding the code to my form php plugin code
PHP:
// Fetch and return content after curl session
$data = curl_exec($ch);
curl_close($ch);

// here is my shortened YOURL

return $data;

$myapp = JFactory::getApplication();
$myapp->enqueueMessage($data);

however nothing happened after the form was submitted.

I also tried putting the code wrapped in php tags into the Form Processing > Success Message but it just returns the code itself as text
Screen-Shot-2020-02-22-at-11-07-30.png
 
Code run after "return" won't run, put it before

$myapp = JFactory::getApplication();
$myapp->enqueueMessage($data);
return $data;
 
That is perfect thank you Troester! Here is the working solution with html mixed in.

PHP:
// Fetch and return content
$data = curl_exec($ch);
curl_close($ch);

// Do something with the result. Return in joomla system message

$myapp = JFactory::getApplication();
$myapp->enqueueMessage("<p>Here is your shortened URL: </p>
<p>Please make a copy of this link and give it to your users</p><hr>
<h2 style='color:red;'>$data</h2>
<hr>
<p><a class ='uk-button uk-button-primary' href='$data' target='_blank'>Test the SHORT Link</a></p>
");

return $data;
 
Last edited:
1. Install Yourls in directory “links” > go to Admin to install
2. add blank index.html to root
3. Activate random in /yourls/admin/plugins.php

To encode your Fabrik URL use a form php plugin and integrate the Yourls api code as below
PHP:
// this is the YOURLS api code
$username = 'myusername';
$password = 'password';

// EDIT THIS: the query parameters
$url     = 'http://yourwebsite.com?option=com_fabrik&view=form&formid=1' .
'&aaa_participant_claim___uniqueclaim_id='. urlencode('{___course_id}') .
'&aaa_participant_claim___category=' . urlencode('{___category_raw}') .
'&aaa_participant_claim___course_title=' . urlencode('{___course_title}') .
'&aaa_participant_claim___course_code=' . urlencode('{___enter_course_code}') .
'&aaa_participant_claim___applysess=' . urlencode('{___apply_sess}') .
'&aaa_participant_claim___allow_overnight=' . urlencode('{___allow_overnight}') .
'&aaa_participant_claim___venue=' . urlencode($ecName).
'&aaa_participant_claim___course_start_date=' . urlencode('{___enter_course_date}') .
'&aaa_participant_claim___claim_process=' . urlencode('{___edcentre_email}') .
'&aaa_participant_claim___edcentre_id=' . urlencode('{___edcentreid}') .
'&aaa_participant_claim___edcentre_process=' . urlencode('{___education_centre}').
'&aaa_participant_claim___venue_ec=' . urlencode($ecEircode);  // URL to shrink

$title   = '{___education_centre}';                // optional, if omitted YOURLS will lookup title with an HTTP request
$format  = 'simple';                       // output format: 'json', 'xml' or 'simple'

// EDIT THIS: the URL of the API file
$api_url = 'http://yourwebsite.com/links/yourls-api.php';

// Init the CURL session
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $api_url );
curl_setopt( $ch, CURLOPT_HEADER, 0 );            // No header in the result
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); // Return, do not echo result
curl_setopt( $ch, CURLOPT_POST, 1 );              // This is a POST request
curl_setopt( $ch, CURLOPT_POSTFIELDS, array(      // Data to POST
    'url'      => $url,
        'keyword'  => $keyword,
        'title'    => $title,
        'format'   => $format,
        'action'   => 'shorturl',
        'username' => $username,
        'password' => $password
    ) );

// Fetch and return content
$data = curl_exec($ch);
curl_close($ch);

// Do something with the result. Return in joomla system message

$myapp = JFactory::getApplication();
$myapp->enqueueMessage("<p>Here is your shortened URL: </p>
<p>Please make a copy of this link and give it to your users</p><hr>
<h2 style='color:red;'>$data</h2>
<hr>
<p><a class ='uk-button uk-button-primary' href='$data' target='_blank'>Test the SHORT Link</a></p>
");

return $data;
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top