1

I have 2 set of fields: Set A (Field1, Field2), and Set B (Field3, Field4).

  • Field1 loads data from Mariadb tableA according to user selection and then loads the corresponding data from tableA to Field2. In order for this to happen, a .php file named 1-2.php is used. Field1 and Field2 work ok but:

Issue for Set A: Inspect Element->Console in the Front End shows all data of the Field2.

  • Field3 loads data from Mariadb tableB according to user selection and then loads the corresponding data from tableB to Field4. In order for this to happen, a .php file named 3-4.php is used. Field3 loads ok from tableB but:

Issue for Set B: Field4 shows nothing!

*Note tableA and tableB structure is identical

1. Set A (Field1 and Field2)

Field1->Actionscript->Custom->Change:

function ff_field1_action(element, action)
{
    switch (action) {
        case 'change':
            jQuery.ajax({
                type: "POST",
                url: "http://someurl/1-2.php",
                data: { field1: element.value },    
                success: function(data) {
                var obj = JSON.parse(data);
                        jQuery('#ff_elem2496').empty();
                       var arr = obj;
                           jQuery('#ff_elem2496').append(jQuery('<option>', {
                                value: '',
                                text: 'whatever'
                            }));
                       for (var i = 0; i < arr.length; i++) { 
                           console.log(arr[i]);
                           jQuery('#ff_elem2496').append(jQuery('<option>', {
                                value: arr[i],
                                text: arr[i]
                            })); 
                        }
                }      
            });
            break;
        default:;
    } // switch
} // ff_field1_action

Note: elem2496 refers to Field2

1-2.php file for Set A:

<?php
define('_JEXEC', 1);
if (file_exists(__DIR__ . '/defines.php'))
{
    include_once __DIR__ . '/defines.php';
}
if (!defined('_JDEFINES'))
{
    define('JPATH_BASE', __DIR__);
    require_once JPATH_BASE . '/includes/defines.php';
}
require_once JPATH_BASE . '/includes/framework.php';
$judgePick1 = JRequest::getVar(field1);
$db1 = JFactory::getDbo();
$query1 = $db1->getQuery(true);
$query1
  ->select('x.name')
  ->from($db1->quoteName('#__tableA', 'x'))
  ->join('LEFT', $db1->quoteName('#__tableA', 'y') . ' ON ' . $db1->quoteName('x.parent') .' = '. $db1->quoteName('y.id'))
  ->where($db1->quoteName('y.name') .' = '. $db1->quote($judgePick1))
  ->andWhere(array($db1->quoteName('x.parent').' = '. $db1->quoteName('y.id'), $db1->quoteName('x.active').' = 1'), $glue = 'AND')
  ->order($db1->quoteName('x.name') . ' ASC');
$db1->setQuery($query1);
$result1 = $db1->loadColumn();
 if(!$result1){
    echo "error";
} else {
    echo json_encode($result1);
}
?>

2. Set B (Field3 and Field4)

Field3->Actionscript->Custom->Change:

function ff_field3_action(element, action)
{
    switch (action) {
        case 'change':
            jQuery.ajax({
                type: "POST",
                url: "http://someurl/3-4.php",
                data: { field3: element.value },    
                success: function(data) {
                var obj = JSON.parse(data);
                        jQuery('#ff_elem3871').empty();
                       var arr = obj;
                           jQuery('#ff_elem3871').append(jQuery('<option>', {
                                value: '',
                                text: 'whatever2'
                            }));
                       for (var i = 0; i < arr.length; i++) { 
                           console.log(arr[i]);
                           jQuery('#ff_elem3871').append(jQuery('<option>', {
                                value: arr[i],
                                text: arr[i]
                            })); 
                        }
                }      
            });
            break;
        default:;
    } // switch
} // ff_field3_action

Note: elem3871 refers to Field4

3-4.php file for Set B:

<?php
define('_JEXEC', 1);
if (file_exists(__DIR__ . '/defines.php'))
{
    include_once __DIR__ . '/defines.php';
}
if (!defined('_JDEFINES'))
{
    define('JPATH_BASE', __DIR__);
    require_once JPATH_BASE . '/includes/defines.php';
}
require_once JPATH_BASE . '/includes/framework.php';
$judgePick2 = JRequest::getVar(field3);
$db2 = JFactory::getDbo();
$query2 = $db2->getQuery(true);
$query2
  ->select('x.name')
  ->from($db2->quoteName('#__tableB', 'x'))
  ->join('LEFT', $db2->quoteName('#__tableB', 'y') . ' ON ' . $db2->quoteName('x.parent') .' = '. $db2->quoteName('y.id'))
  ->where($db2->quoteName('y.name') .' = '. $db2->quote($judgePick2))
  ->andWhere(array($db2->quoteName('x.parent').' = '. $db2->quoteName('y.id'), $db2->quoteName('x.active').' = 1'), $glue = 'AND')
  ->order($db2->quoteName('x.name') . ' ASC');
$db2->setQuery($query2);
$result2 = $db2->loadColumn();
if(!$result2){
    echo "error";
} else {
    echo json_encode($result2);
}
?>

Finally, in Form->Advanced->More Options->Form Pieces->Before Form:

// Set A 
$this->execPieceByName('ff_InitLib'); //Include BreezingForms Library
$db1 = JFactory::getDBO();//Get Database Object
$db1->setQuery('SELECT name FROM #__tableA WHERE parent=0 AND active=1 ORDER BY id ASC');
$result1 = $db1->loadColumn(); //load the result from the query
$res1 = "0;whatever;0\n";
for ($i = 0; $i < count($result1); $i++)
{
     $res1 .= "0;".$result1[$i].";".$result1[$i]."\n";
}
 function ff_setSelectList1($name, $value)
{
     global $ff_processor;
     for ($r = 0; $r < $ff_processor->rowcount; $r++)
     {
          $row =& $ff_processor->rows[$r];
          if ($row->name==$name)
          $row->data2 = $value;
          unset($row);
     } // for
} // ff_setSelectList1
 ff_setSelectList1('field1', $res1);

// Set B 
$this->execPieceByName('ff_InitLib'); //Include BreezingForms Library
$db2 = JFactory::getDBO();//Get Database Object
$db2->setQuery('SELECT name FROM #__tableB WHERE parent=0 AND active=1 ORDER BY id ASC');
$result2 = $db2->loadColumn(); //load the result from the query
$res2 = "0;whatever2;0\n";
for ($i = 0; $i < count($result2); $i++)
{
     $res2 .= "0;".$result2[$i].";".$result2[$i]."\n";
}
function ff_setSelectList2($name, $value)
{
     global $ff_processor;
     for ($r = 0; $r < $ff_processor->rowcount; $r++)
     {
          $row =& $ff_processor->rows[$r];
          if ($row->name==$name)
          $row->data2 = $value;
          unset($row);
     } // for
} // ff_setSelectList2
ff_setSelectList2('field3', $res2);

The structure of Table A and Table B is the following:

Id  parent  name        uri         active
1   0       greekname1  latinname1  1
2   0       greekname2  latinname2  1
3   0       greekname3  latinname3  1
4   1       greekname4  latinname4  1
5   1       greekname5  latinname5  1
6   2       greekname6  latinname6  1
7   3       greekname7  latinname7  1
33
  • @mickmackusa First of all, thanks for having a look at it. The part that you mention is exactly as suggested by BreezingForms website and forum. I tried contacting Crosstec before postng here but sadly I was informed that they are facing a covid19 issue. Therefore, I was trying to figure out the proper syntax myself for "// Set B" as this looks to me to be the cause of the "Issue for Set B", but didn't work good so far. As for the "Issue for Set A" I tried removing "// Set B" but it went on appearing. So it must be irrelevant. Thanks
    – GalanopD
    Apr 19 '20 at 22:15
  • I may need to ask for proof that this is a coding problem versus a data problem. Are you able to definitively rule out the notion that there is simply no qualifying data in table 4 that relates to the selection in table 3? Please see this recent post which offers diagnostic techniques: joomla.stackexchange.com/a/27909/12352 this may uncover some new clues.
    – mickmackusa
    Apr 20 '20 at 4:26
  • I thought I found the fatal typos. Look at JRequest::getVar(field1); and JRequest::getVar(field3); these attempts to grab submitted values are using an undefined CONSTANT called field#, but you want to access the values relating to the string keys, so you must wrap those words in single or double quotes. Actually, these are not fatal, they will merely generate warnings. 3v4l.org/QgJ0L so this is not a resolving fix. I'm afraid I am going to need to know the incoming value and your database schema.
    – mickmackusa
    Apr 20 '20 at 7:09
  • The 2 tables have identical structure. Therefore, why table A works fine for Field Set A and table B doesn’t for Field Set B? The Field1, Field2, Field3, Field4, are the names of the fields. I have used Field1, Field2, etc as an example for JSE. Maybe I should have used Fieldname1, Fieldname2, etc. Field Set B loads data from the table B only to Field3, and when you select an option, nothing appears to Field4. This doesn’t happen in case of Set Fields A where Field1 loads data from table A and when you make your selection Field2 brings the corresponding data from the table. Structure posted.
    – GalanopD
    Apr 20 '20 at 12:50
  • So the structures are identical, but the values differ, so we need to review the actual data. Are you printong the judgepicks to screen? Did you run my recommended diagnostics?
    – mickmackusa
    Apr 20 '20 at 12:58

Browse other questions tagged or ask your own question.