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

php8.1 form php plugin not executing

Discussion in 'Community' started by ontarget, Oct 4, 2022.

  1. ontarget

    ontarget Active Member

    Level: Community
    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?

    Here is the code in the php form plugin.

    $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);

    // 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>
    <p><a class ='uk-button uk-button-primary' href='$data' target='_blank'>Test the SHORT Link</a></p>

    return $data;
  2. lousyfool

    lousyfool Well-Known Member

    Level: Community
    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?
    ontarget likes this.
  3. ontarget

    ontarget Active Member

    Level: Community
    Thanks for the suggestions.
    The code above works fine in php7.4
    I will make those changes and test again in php8.1
  4. ontarget

    ontarget Active Member

    Level: Community
  5. achartier

    achartier Active Member

    Level: Community
    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.
    ontarget likes this.
  6. achartier

    achartier Active Member

    Level: Community
    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.
  7. ontarget

    ontarget Active Member

    Level: Community
    @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?

    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: Oct 6, 2022
  8. troester

    troester Well-Known Member Staff Member

    Level: Community

Share This Page