TOPIC:

Multiple Dynamic Select Lists from DB 11 months 6 days ago #237609

  • Topic Author
  • kenryanjr
  • Offline
  • Senior Breezer
  • Senior Breezer
  • Posts: 144
  • Thanks: 0
I am building a vehicle classifieds application with Breezing Forms Pro 1.9.0 Stable (931) and Content Builder 0.9.91 (build 252) on Joomla 3.9.11.

I am building the Vehicle Make select list out of the database with no issues using this code in the Form Pieces/Before Form/Custom section.
$this->execPieceByName('ff_InitLib');
 
$rows = ff_select("select id, make from #__car_makes order by make asc"); $listdata = ";Select Vehicle Make;\n"; for ($i = 0; $i < count($rows); $i++) {
                $listdata .= "0;{$rows[$i]->make};{$rows[$i]->make}\n";
}
ff_setSelectList('vehicleMake', $listdata);
 
function ff_setSelectList($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_setSelectList

Where I am having trouble is building the Vehicle Model select list based on the Vehicle Make that the user selects.

car_make table has an id field and make field
car_model table has and id field, carmodel field, and a make_id field.

I have seen several different variations of this in the forum but can't seem to find what I need to make this work.

I tried this one and built a php page that would post back the data but kept getting a 500 error. crosstec.org/en/forums/30-tips-tricks/99...ng-on-selection.html

crosstec.org/en/forums/1-forums/125334-m...om-list.html?start=0

This doesn't seem to be really hard, but I am not a fantastic coder as I am out of practice and haven't really done a lot of complicated coding.

Please Log in or Create an account to join the conversation.

Multiple Dynamic Select Lists from DB 11 months 5 days ago #237620

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 414
Hello,

If I have understood correctly, you populate the first select list vehicleMake with the options from the database.

Would you then like to fill in the next select list BASED on what was selected in the " vehicleMake" select list, or you just want this select list to be filled in from database regardless of what was selected in the "vehicleMake "?

Regards,

Mihaela

Please Log in or Create an account to join the conversation.

Multiple Dynamic Select Lists from DB 11 months 5 days ago #237635

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 414
Hi again,

I've seen your post on Discord:
"Where I am having trouble is building the Vehicle Model select list based on the Vehicle Make that the user selects."
That is basically the answer to make questions so I will give you instructions on how to do so.

In this topic that you have linked here the solution to your question is provided crosstec.org/en/forums/1-forums/125334-m...m-list.html?start=24 .
You should just read it carefully.

I can give you an example.
So you have to go to the Advanced properties of vehicleMake element. In the Actionscript section set Type to Custom and Action to Change.
Then in the code area below put the code similar to this one:
function ff_vehicleMake_action(element, action)
{
    switch (action) {
        case 'change':
            jQuery.ajax({
                type: "POST",
                url: "http://localhost/value.php",
                data: { vmake : element.value },    
                success: function(data) {
                var obj = JSON.parse(data);
                        jQuery('#ff_elem7509').empty();
                       var arr = obj;
                       jQuery('#ff_elem7509').append(jQuery('<option>', {
                                value: '',
                                text: 'Choose option'
                            }));
                       for (var i = 0; i < arr.length; i++) { 
                           console.log(arr[i]);
                           jQuery('#ff_elem7509').append(jQuery('<option>', {
                                value: arr[i],
                                text: arr[i]
                            })); 
                        }
                }      
            });
            break;
        default:;
    } // switch
} // ff_vehicleMake_action
NOTE: In the code above you have to replace http://localhost/value.php with the correct path to the value.php file that you will create in Joomla root folder.

Also, replace ff_elem7509 with the correct ID of the second Vehicle Model select list that you can get by inspecting that element in your form.

Then go to the Joomla root folder and create there file named value.php with the following content:
<?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';

$vehMake = JRequest::getVar('vmake'); 

$db = JFactory::getDBO();
$db->setQuery('SELECT `carmodel` FROM `TABLENAME` WHERE make_id ='.$db->quote($vehMake)); 
$result = $db->loadColumn();
 if(!$result){
 	echo "error";
} else {
	echo json_encode($result);
}
NOTE: In this code, you have to replace the current database query which works with the query in this case. This would work if the value of first select list is the make_id.

Let me know whether you have managed to adjust this for your case.

Regards,

Mihaela

Please Log in or Create an account to join the conversation.

Multiple Dynamic Select Lists from DB 11 months 5 days ago #237642

  • Topic Author
  • kenryanjr
  • Offline
  • Senior Breezer
  • Senior Breezer
  • Posts: 144
  • Thanks: 0
I am sure I am going to have more questions as I move forward, but that worked perfectly. Thank you!

Please Log in or Create an account to join the conversation.

Multiple Dynamic Select Lists from DB 11 months 4 days ago #237646

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 414
Hello,

Great! I'm glad I've helped and that it is working for you.

Regards,

Mihaela

Please Log in or Create an account to join the conversation.

Multiple Dynamic Select Lists from DB 10 months 4 weeks ago #237754

  • Topic Author
  • kenryanjr
  • Offline
  • Senior Breezer
  • Senior Breezer
  • Posts: 144
  • Thanks: 0
How can I order by the carmodel in this code? I have tried every combination I know and nothing works.
<?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';

$vehMake = JRequest::getVar('vmake'); 

$db = JFactory::getDBO();
$db->setQuery('SELECT `carmodel` FROM `TABLENAME` WHERE make_id ='.$db->quote($vehMake)); 
$result = $db->loadColumn();
 if(!$result){
 	echo "error";
} else {
	echo json_encode($result);
}

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
  • 2
Moderators: ForumSupport
Time to create page: 0.044 seconds

BreezingForms Pro 1.4.7 for WordPress Released!

Available in the membership section.

Summer Sale!

Massive discounts on all subscriptions!

Get Your Subscription Here

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Special Offer

Summer Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!