Quantcast
Channel: Joomla! Forum - community, help and support
Viewing all articles
Browse latest Browse all 1465

Extensions for Joomla! 4.x • BreezingForms/Joomla4/Dynamic Dropdown Population issue

$
0
0
Hello everyone,

I am in the process of upgrading a working Breezingforms form from a Joomla3 site to Joomla4. BreezingForms is used to handle the form submission with dynamic dropdowns that fetch data via an AJAX request to a PHP script named "subcat.php". This setup works perfectly on Joomla3 but has issues on Joomla4 and I am not sure if the issue is Breezingforms related or something else is wrong.

Javascript Code inside form's field sends an AJAX request to subcat.php in Joomla's root folder, based on user input.
Form Element uses dropdown that is dynamically populated based on AJAX response. The "subcat.php" handles the AJAX request from field elem14004, queries the database, and returns JSON data for populating the dropdown in field elem14005 inside the form.

Problem:
When migrating to Joomla4, the subcat.php script fails to initialize the Joomla application, resulting in the following error when accessed directly or via AJAX:

json

{
"error": "Failed to start application",
"details": "Failed to start application",
"log": [
"Base path: /var/www/vhosts/my_website/httpdocs",
"includes/defines.php found.",
"includes/framework.php found.",
"configuration.php found.",
"PHP extension mysqli is loaded",
"PHP extension json is loaded",
"PHP extension curl is loaded",
"PHP extension mbstring is loaded",
"Attempting to initialize the Joomla application...",
"Exception during Joomla application initialization: Failed to start application"
]
}

I have verified the presence and permissions of defines.php, framework.php, and configuration.php and they are 644. I have confirmed required PHP extensions (mysqli, json, curl, mbstring) are loaded in any case.

I have also updated subcat.php (after trying using Joomla's default with no success) to utilize BreezingForms-specific database and request handling methods (BFFactory::getDbo() and BFRequest::getVar()) following Crosstec's page announcement related to "Upgrading to Joomla4 and PHP8" although the subcat.php is not inside the form e.g. in the "Before form" but in Joomla's root folder:
From Crosstec forum:
If you use custom scripts and pieces, chances are high your custom code won't work against Joomla4 and/or PHP8 any longer. There may be numerous reasons to upgrade custom code. Here are the most important ones:

- Replace all occurences of JFactory::getDbo() with BFFactory::getDbo()
(this only affects getDbo(), other cases of using JFactory are not affected)

- Replace all occurences of "JRequest::" with "BFRequest::" or use "JFactory::getApplication()->input" (see Joomla Docs)
I have ensured proper inclusion of Joomla and BreezingForms initialization files.

Debugging steps:
Verified that elem14005 targets the correct form field. Added detailed logging to identify the point of failure in the initialization process. Verified the base path and file inclusions during script execution.

Relevant Code Snippets:
Javascript (AJAX Request)

Code:

function ff_branchtypevehicle_action(element, action) {    if (action === 'change') {        jQuery('#ff_elem14005').empty().append(jQuery('<option>', {            value: '',            text: 'some text'        }));        jQuery.ajax({            type: "POST",            url: "https://my_website/subcat.php",            data: { branchtypevehicle: element.value },            success: function(data) {                var arr = JSON.parse(data);                jQuery.each(arr, function(index, value) {                    jQuery('#ff_elem14005').append(jQuery('<option>', {                        value: value,                        text: value                    }));                });            }        });        // Conditional fields toggling...    }}
PHP Script (subcat.php)

Code:

<?phpini_set('display_errors', 1);error_reporting(E_ALL);header('Access-Control-Allow-Origin: https://my_website');header('Content-Type: application/json');define('_JEXEC', 1);define('JPATH_BASE', __DIR__);if (file_exists(JPATH_BASE . '/defines.php')) {    include_once JPATH_BASE . '/defines.php';}if (!defined('_JDEFINES')) {    require_once JPATH_BASE . '/includes/defines.php';}require_once JPATH_BASE . '/includes/framework.php';require_once JPATH_BASE . '/administrator/components/com_breezingforms/libraries/crosstec/constants.php';require_once JPATH_BASE . '/administrator/components/com_breezingforms/libraries/crosstec/classes/BFFactory.php';require_once JPATH_BASE . '/administrator/components/com_breezingforms/libraries/crosstec/classes/BFRequest.php';require_once JPATH_BASE . '/administrator/components/com_breezingforms/libraries/crosstec/functions/helpers.php';$app = JFactory::getApplication('site');$app->initialise();$input = BFRequest::getVar('branchtypevehicle', '', 'default', 'string');if (empty($input)) {    echo json_encode(['error' => 'branchtypevehicle parameter is missing']);    exit;}$db = BFFactory::getDbo();$query = $db->getQuery(true);$query->select($db->quoteName('x.name'))      ->from($db->quoteName('#__vehicles_categ', 'x'))      ->join('LEFT', $db->quoteName('#__vehicles_categ', 'y') . ' ON ' . $db->quoteName('x.parent') . ' = ' . $db->quoteName('y.id'))      ->where($db->quoteName('y.name') . ' = ' . $db->quote($input))      ->where($db->quoteName('x.active') . ' = 1')      ->order($db->quoteName('x.name') . ' ASC');$db->setQuery($query);$result = $db->loadColumn();if (!$result) {    echo json_encode(['message' => 'No results']);} else {    echo json_encode(['data' => $result]);}?>
I don't know what else to try apart from changing to another component (complicated form and I don't want to start from scratch again...) and I am out of ideas. Seeking assistance in resolving the initialization issue of the Joomla application within subcat.php. Anyway, although I have verified configurations, permissions, and required extensions, the script fails to start the Joomla application.

Joomla 4.4.5
PHP 8.1.29
MariaDB 10.6.18

Thank you in advance for taking the time to have a look at it,
Best

Statistics: Posted by galanopd — Tue Jun 11, 2024 6:40 pm



Viewing all articles
Browse latest Browse all 1465

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>