• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

php8.1 form php plugin not executing

ontarget

Active Member
Hi I have just upgraded a fabrik 3.1system to php8.1
Similar to https://fabrikar.com/forums/index.php?threads/form-email-plugin-doesnt-send-mails-in-php8.53466/
I have a php form plugin set to onAfterProcess In Both on New
After submitting the form its supposed to execute the following php ( generating a shortened url using yourls API)
However nothing happens - it just submits and the php is not being executed
Is this a known issue?
Thanks


Here is the code in the php form plugin.
PHP:
$username = 'xxxxxxx';
$password = 'xxxxxxx';


$url= 'https://xxxxxxx.ie/index.php?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('{___calcvenuename}').
'&aaa_participant_claim___course_start_date=' . urlencode('{___enter_course_date}') .
'&aaa_participant_claim___course_hours=' . urlencode('{___course_hours}') .
'&aaa_participant_claim___tutor_preparation_hours=' . urlencode('{___tutor_preparation_hours}') .
'&aaa_participant_claim___course_during_school=' . urlencode('{___course_during_school}') .
'&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('{___calcvenueeircode}');  

$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 = 'https://xxxx.ie/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. Here, we just echo it.

$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;
 
First, and as usual: don't forget that for debugging your code you can always print_r or var_dump variables followed by "exit;" to see what you're getting.
Can't comment on the API, you'll have to refer to its documentation and/or test it separately.

Other things that come to mind after a quick glance:

E.g. "urlencode('{___course_id}')": Are you getting what you want?
Same for all other element placeholders, including those which might be e.g. arrays and/or in repeat groups?
For getting form data and else, the Wiki is your friend.

Variable $data: Consider using a different name as $data is often already used for other purposes in Fabrik (again, see Wiki).

PHP variable in the message text: Looks to me as if it should throw syntax errors?
 
Thanks for the suggestions.
The code above works fine in php7.4
I will make those changes and test again in php8.1
 
I see the problem. When a form is opened for edit to existing rowID is not being set so the form onAfterProcess is only running on new. if you set it to Edit then the plugin will not run. More investigation required.
 
OK, so I am not sure why this is happening in F3. I found the issue in F4 but it was caused by something else we changed to fix a php8.1 deprecated warning (fixed the warning, broke the code). One way you can check if you have the same problem, open a list view and then with the browser developers interface inspect the element that links to the record. Check that the link includes the data-rowid=xx (where xx is the row number). If the =xx is missing then it may be the same problem and I can tell you what you need to do.
 
@achartier Thanks for the reply.
In my situation the fabrik form (1) is not submitting any element data to a fabrik list
All the elements are set to "Save to Database = No".
The php form plugin generates a short (yourls) link - only the generated link is posted to my yourls admin area / db table

Therefore I can't do the following:
Open list view and then with the browser developers interface inspect the element that links to the record:
Check that the link includes the data-rowid=xx

This is what is happening in my situation
  • The form php plugin in form(1) grabs the element data and generates a short link with it.
  • Form(1) is set to onAfterProcess Both / New (this setting doesn't work and the php plugin doesn't run)
  • No record is posted from the php form plugin to my yourls short url admin area
  • I tried Changing the js event handlers e.g to onSavePage / getEndContent but this doesn't make a difference.
What does work with php8.1
  • Changing Form (1) to onAfterProcess Both / Both does allow the php plugin to fire.
  • The enduser clicks the short link and the url pre-populates fields in a new fabrik form(2).
  • The data is submitted from fabrik form(2) to the database (this step works fine).
Do you think that the data not being submitted to a fabrik list / db table from form(1) is therefore the issue?

Update:
I can confirm that this behaviour with Both / New also affects other form plugins e.g the redirect plugin so its must something to do with a null value when New is selected?
 
Last edited:
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top