Forums

ChronoForms Multiple Dropdown | Multiple Querys

diogoribeiro 03 Nov, 2012
Hi you all,
first off all i have to thank you for the wonderful job you're making. Chronoforms is really amazing.
Well, i'm having a few problems coding some stuff that i need. I have a Website that provides learning courses which are inserted in a database. The desired behaviour is - i click on one item in the first drop down menu ( containing all my course's category's ), the second drop down is filled with information asked to the database depending on what item you clicked first, the same process for the 3rd drop down. It is important to state that all the 3 levels are not in the same database table, as you can see in the next presented code.

Note: I have not implemented the 3rd drop down behaviour yet as it is identical to the 2nd.

My code :

<?php

$options = array();
$options[] = "<option value=''>--?--</option>";
$options1 = array();
$options1[] = "<option value=''>--?--</option>";
$options2 = array();
$options2[] = "<option value=''>--?--</option>";
$db =& JFactory::getDBO();
$query = "
  SELECT `id`, `tipo`
    FROM `formacao`;
";
$db->setQuery($query);
$data = $db->loadObjectList();
foreach ( $data as $d ) {
  $options[] = "<option value='{$d->id}'>{$d->tipo}</option>";
}
if($d->tipo=="Financiada")
{
	$query = "
	  SELECT `id`, `area_formacao`
	    FROM `ffinanciada`;
	";
	$db->setQuery($query);

	$data1 = $db->loadObjectList();
	foreach ( $data1 as $d1 ) {
	  $options1[] = "<option value='{$d1->id}'>{$d1->area_formacao}</option>";
	}
}
elseif($d->tipo=="Não Financiada")
{
	$query = "
	  SELECT `id`, `area_formacao`
	    FROM `fnfinanciada`;
	";
	$db->setQuery($query);
	$data1 = $db->loadObjectList();
	foreach ( $data1 as $d1 ) {
	  $options1[] = "<option value='{$d1->id}'>{$d1->area_formacao}</option>";
	}
}
elseif($d->tipo=="Comparticipada a 75%")
{
	$query = "
	  SELECT `id`, `area_formacao`
	    FROM `comparticipada`;
	";
	$db->setQuery($query);
	$data1 = $db->loadObjectList();
	foreach ( $data1 as $d1 ) {
	  $options1[] = "<option value='{$d1->id}'>{$d1->area_formacao}</option>";
	}
}
elseif($d->tipo=="Empresas")
{
//TO DO
}
else
{
/TO DO	
}

?>
<select class="" id="1" size="1" name="1Nivel">
<?php echo implode("\n", $options); ?>
</select>

<select class="" id="2" size="1" name="2Nivel">
<?php echo implode("\n", $options1); ?>
</select>

<select class="" id="3" size="1" name="3Nivel">
<?php echo implode("\n", $options2); ?>
</select>


Actually, is my first time dealing with php.
Best Regards,
Diogo Ribeiro
GreyHead 04 Nov, 2012
Hi diogoribeiro,

Please check the FAQs for double dropdowns. There is also a tutorial that you can buy from my site at greyhead.net with some code examples.

Bob
diogoribeiro 05 Nov, 2012
Hi,
thanks for the reply. Actually , my problem is not creating the drop downs... They show up and assume the default value. My problem is, although the first drop down shows the info queried from the DB, the second and third remain the same. I believe the second DB Query is not working ( the SQL part i'm sure it is ) or i'm missing some php part. I don't even know how to confirm that the flow really goes trough my if/else statement.
Best Regards,
Diogo Ribeiro
GreyHead 06 Nov, 2012
Hi Diogo,

I'm not sure that I understand the problem. I can take a look next week when I'm back in the office.

Bob
diogoribeiro 07 Nov, 2012
Hi Bob,

maybe i didn't explained myself correctly. As you can see from the code, the drop down menus should/do appear on my website. Problem is, i cannot fill the second drop down menu, it runs as i never did the second query to the DB. The thing is, i have different tables that are not connected (SQL speaking) because they were created with Fabrik's plugin. So, what i have to do is : based on the item selected on the first drop down menu, i pick a certain table to query ( thats the reason for the if/else ). With the information queried from the DB i fulfil the second drop down menu. Do the same for the third drop down menu.

Best Regards,
Diogo Ribeiro
Max_admin 08 Nov, 2012
Hi Diogo,

So how do you expect the next dropdowns to be changed ? do you submit the form after teh first selection or do you have some AJAX code ?

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
diogoribeiro 12 Dec, 2012
Sorry for the late reply but my host provider had some problems and my website was down.
I have no ideia how make this. I have no AJAX code and i'm really lost in the process.
Best Regards,
Diogo Ribeiro
diogoribeiro 12 Dec, 2012
Actually i bought Greyhead's article "Build a ‘double drop-down’ using Ajax" and so far so good. Only problem i'm experiencing is in the it says :
"We are going to add our server-side code to the ChronoForms Extra Code 1 box which sits near the bottom of the Form Code tab in the Form Editor along with its sisters: Extra Code 2 - 5."

As i can't find this box , i'm stuck .

Little help, here?
GreyHead 12 Dec, 2012
Hi diogoribeiro,

That was true in CFv3. In CFv4 you need to add a new Event Using the Add Event button and add the code there - probably using a Custom Code action. There's an example in this FAQ

Bob
This topic is locked and no more replies can be posted.