How to Create a Dynamic Drop-down List

belmond 02 Apr, 2014
I'm new to chronoforms. Can somebody help me in my problem. I need step by step process for creating a dynamic drop-down list. Thanks in advance
Max_admin 02 Apr, 2014
Hi Belmond,

How do you want the dropdown to work exactly ? did you check the demo form in v5 ? it already has a demo for this feature!

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
belmond 02 Apr, 2014
i would like to call data's from my database. Can't find the demo for this. Example I have my table of events. I want all data's will be called and be on my dropdown or combo box.
Max_admin 02 Apr, 2014
Please check this page then:
http://www.chronoengine.com/faqs/58-cfv4/cfv4-elements-and-html/2647-how-do-i-build-a-select-drop-down-radio-button-or-checkbox-group.html

However, please note that in v5 there is the "DB Read" action instead of the "DB multi record loader", which you will need to read the data from the database!
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
belmond 03 Apr, 2014
I have here the data's from my event tables

- Festival
- Musical
- Competition
- etc.

How can I put this to my drop-down using dynamic data. Can u please help me.
belmond 03 Apr, 2014
I don't know what to put on data path, value key and text key
GreyHead 03 Apr, 2014
Hi belmond,

Please only post your questions once in the forums here. Posting the same question twice and emailing it wastes your time and ours.

Please write a full description of what the problem is. If English isn't your first language it's OK to post the original and a Google translation - that is more helpful than a few very brief notes that don't explain the problem clearly.

Please check the section in this FAQ headed "Dynamic Data from a database table" which kalkal posted in reply to another copy of your post here.

Bob
admin_wiky 21 Aug, 2014
How Can I use this for CCv5?
I tried to use code from CFv5, where data are loader to the form:
<?php
$keys = \GCore\Libs\Arr::getVal(\GCore\Libs\Arr::getVal($form->data, explode(".", "zakladni")), explode(".", "[n].filialka_id"));
$values = \GCore\Libs\Arr::getVal(\GCore\Libs\Arr::getVal($form->data, explode(".", "zakladni")), explode(".", "[n].filialka_id"));
$options = array_combine($keys, $values);
$field = array (
  'name' => 'zakladni[datum]',
  'id' => 'league',
  'options' => 
  array (
  ),
  'empty' => 'Seletc your team\'s league/devision',
  'values' => 
  array (
  ),
  'label' => 
  array (
    'text' => 'Dropdown Label',
    'position' => 'left',
  ),
  'sublabel' => '',
  'multiple' => '0',
  'size' => '',
  'class' => '',
  'title' => '',
  'style' => '',
  'params' => '',
  ':data-load-state' => '',
  ':data-tooltip' => '',
  'type' => 'dropdown',
  'container_id' => '0',
);
$field["options"] = $options;
echo \GCore\Helpers\Html::formLine($field["name"], $field);
?><div class="form-group gcore-form-row" id="form-row-1"><div class="gcore-input gcore-display-table" id="fin-button3"><input name="button3" id="button3" type="submit" value="Submit" class="form-control A" style="" data-load-state="" /></div></div>

but doesnt work in CCv5 added to header code in list display as table.
thx
Max_admin 22 Aug, 2014
Hi homepat,

The new update for CFv5 (just released) has a demo form demonstrating this feature, its named "dynamic data dropdown", please check it!

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
admin_wiky 25 Aug, 2014
Hi max,

I have it, RC4 from may 2014. This code used in CFv5 works, but if I put him to the CCv5 then data arent loaded to the dropdown.

thx
GreyHead 25 Aug, 2014
Hi homeopat,

Which version of ChronoForms are you using?

If it is CFv5 please see Max's post here.

If it is CFv4 please check the FAQs for directions.

Bob
admin_wiky 25 Aug, 2014
Hi Bob,

all versions are 5. I used a demo form, modify it and it works .. but this code doesnt work If I use this code in CCv5.
Max_admin 25 Aug, 2014
The code is dependent on some data to be available, just try to use your form in CCv5, by using its name in the "Actions" section.
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
admin_wiky 25 Aug, 2014
but I want use dropdown for selection of date in Chronoconnection list ... or can I call an action in custom code (table)?
Max_admin 29 Aug, 2014
The code can be reused in CC, but you will have to edit it of course, since you need to capture the data in CC, then at least you will have to change $form->data to $row, I didn't test this myself though!

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
admin_wiky 01 Sep, 2014
Hi max,
I am not sure, if I have to change $form->data to $row or something else?
I modify the form code:
<?php
$keys = \GCore\Libs\Arr::getVal(\GCore\Libs\Arr::getVal($row, explode(".", "zakladni")), explode(".", "[n].datum"));
$values = \GCore\Libs\Arr::getVal(\GCore\Libs\Arr::getVal($row, explode(".", "zakladni")), explode(".", "[n].datum"));
$options = array_combine($keys, $values);
$field = array (
  'name' => 'zakladni[datum]',
  'id' => '',
  'options' => 
  array (
  ),
  'empty' => '',
  'values' => 
  array (
  ),
  'label' => 
  array (
    'text' => 'Dropdown Label',
    'position' => 'left',
  ),
  'sublabel' => '',
  'multiple' => '0',
  'size' => '',
  'class' => '',
  'title' => '',
  'style' => '',
  'params' => '',
  ':data-load-state' => '',
  ':data-tooltip' => '',
  'type' => 'dropdown',
  'container_id' => '0',
);
$field["options"] = $options;
echo \GCore\Helpers\Html::formLine($field["name"], $field);
?><div class="form-group gcore-form-row" id="form-row-1"><div class="gcore-input gcore-display-table" id="fin-button3"><input name="button3" id="button3" type="submit" value="Submit" class="form-control A" style="" data-load-state="" /></div></div>


but it doesnt work
thx
Max_admin 05 Sep, 2014
Your change is correct, but maybe the structure of the array in $row is different of that in $form->data, please use the "pr" function to check both:
pr($form->data);
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
admin_wiky 05 Sep, 2014
Hi Max,

pr($row) returns debugger data, but only in body section (not in header section - empty).
So I put the form code to the body section, but data didnt loaded to the dropdown.

I need the dropdown in header section
Max_admin 07 Sep, 2014
Ok, what's the data source from which you plan to populate the dropdown then ?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
admin_wiky 08 Sep, 2014
I dont uderstands your question. from the same table as is main table in CC
Max_admin 09 Sep, 2014
Ok, please try to use "$rows" instead of "$row" since this is in the header section.
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
admin_wiky 09 Sep, 2014
do u mean change $row to $rows in previous code of form?
doesnt work.
Max_admin 10 Sep, 2014
Yes!

Ok, now you need to debug this, please try pr($rows), does it return the data of the list ?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
admin_wiky 10 Sep, 2014
Hi Max,

if I use pr($rows) in header section, data of debugger are loaded.

If i put the code to header section then dropdown is empty> no data

    <?php
    $keys = \GCore\Libs\Arr::getVal(\GCore\Libs\Arr::getVal($rows, explode(".", "zakladni")), explode(".", "[n].datum"));
    $values = \GCore\Libs\Arr::getVal(\GCore\Libs\Arr::getVal($rows, explode(".", "zakladni")), explode(".", "[n].datum"));
    $options = array_combine($keys, $values);
    $field = array (
      'name' => 'zakladni[datum]',
      'id' => '',
      'options' => 
      array (
      ),
      'empty' => '',
      'values' => 
      array (
      ),
      'label' => 
      array (
        'text' => 'Dropdown Label',
        'position' => 'left',
      ),
      'sublabel' => '',
      'multiple' => '0',
      'size' => '',
      'class' => '',
      'title' => '',
      'style' => '',
      'params' => '',
      ':data-load-state' => '',
      ':data-tooltip' => '',
      'type' => 'dropdown',
      'container_id' => '0',
    );
    $field["options"] = $options;
    echo \GCore\Helpers\Html::formLine($field["name"], $field);
    ?><div class="form-group gcore-form-row" id="form-row-1"><div class="gcore-input gcore-display-table" id="fin-button3"><input name="button3" id="button3" type="submit" value="Submit" class="form-control A" style="" data-load-state="" /></div></div>

thank you
Max_admin 10 Sep, 2014
So the pr($rows) lists your data ? if yes then please test this line:
pr($options);

after
$options = array_combine($keys, $values);
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
admin_wiky 11 Sep, 2014
empty result after modification of code in header section:
  <?php
        $keys = \GCore\Libs\Arr::getVal(\GCore\Libs\Arr::getVal($rows, explode(".", "zakladni")), explode(".", "[n].datum"));
        $values = \GCore\Libs\Arr::getVal(\GCore\Libs\Arr::getVal($rows, explode(".", "zakladni")), explode(".", "[n].datum"));
        $options = array_combine($keys, $values);
        pr($options);
        $field = array (
          'name' => 'zakladni[datum]',
          'id' => '',
          'options' => 
          array (
          ),
          'empty' => '',
          'values' => 
          array (
          ),
          'label' => 
          array (
            'text' => 'Dropdown Label',
            'position' => 'left',
          ),
          'sublabel' => '',
          'multiple' => '0',
          'size' => '',
          'class' => '',
          'title' => '',
          'style' => '',
          'params' => '',
          ':data-load-state' => '',
          ':data-tooltip' => '',
          'type' => 'dropdown',
          'container_id' => '0',
        );
        $field["options"] = $options;
        echo \GCore\Helpers\Html::formLine($field["name"], $field);
        ?><div class="form-group gcore-form-row" id="form-row-1"><div class="gcore-input gcore-display-table" id="fin-button3"><input name="button3" id="button3" type="submit" value="Submit" class="form-control A" style="" data-load-state="" /></div></div>
Max_admin 11 Sep, 2014
Please post a full or partial report for the debug of the $rows variable, you can change/remove any sensitive data.

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
admin_wiky 11 Sep, 2014
problem is that debugger box is empty.
here is report of pr($rows) showing first two and last record:

Array
(
    [0] => Array
        (
            [zakladni] => Array
                (
                    [cf_id] => 1
                    [cf_uid] => 
                    [cf_created] => 0000-00-00 00:00:00
                    [cf_modified] => 2014-09-02 08:49:31
                    [cf_created_by] => 0
                    [cf_modified_by] => 541
                    [cf_ipaddress] => 
                    [cf_user_id] => 0
                    [filialka_id] => 501
                    [datum] => 2014-07-15
                    [hotovost_kc] => 800
                    [hotovost_euro] => 0
                    [kurz_euro] => 0
                    [celkem_euro] => 0
                    [platebni_karty] => 0
                    [poukazy_p] => 0
                    [poukazy_uplatnene] => 0
                    [drobna_vydani] => 0
                    [mzdy] => 0
                    [postovne] => 0
                    [cestovne] => 0
                    [odvod_kb] => 400
                )

        )

    [1] => Array
        (
            [zakladni] => Array
                (
                    [cf_id] => 2
                    [cf_uid] => 
                    [cf_created] => 0000-00-00 00:00:00
                    [cf_modified] => 0000-00-00 00:00:00
                    [cf_created_by] => 0
                    [cf_modified_by] => 0
                    [cf_ipaddress] => 
                    [cf_user_id] => 0
                    [filialka_id] => 501
                    [datum] => 2014-07-16
                    [hotovost_kc] => 1600
                    [hotovost_euro] => 0
                    [kurz_euro] => 0
                    [celkem_euro] => 0
                    [platebni_karty] => 0
                    [poukazy_p] => 0
                    [poukazy_uplatnene] => 0
                    [drobna_vydani] => 0
                    [mzdy] => 0
                    [postovne] => 0
                    [cestovne] => 0
                    [odvod_kb] => 1000
                )

        )
....
    [20] => Array
        (
            [zakladni] => Array
                (
                    [cf_id] => 21
                    [cf_uid] => 
                    [cf_created] => 2014-09-10 12:18:17
                    [cf_modified] => 0000-00-00 00:00:00
                    [cf_created_by] => 543
                    [cf_modified_by] => 0
                    [cf_ipaddress] => 109.81.198.1
                    [cf_user_id] => 543
                    [filialka_id] => 553
                    [datum] => 2014-09-09
                    [hotovost_kc] => 20285
                    [hotovost_euro] => 0
                    [kurz_euro] => 0
                    [celkem_euro] => 0
                    [platebni_karty] => 4216
                    [poukazy_p] => 0
                    [poukazy_uplatnene] => 0
                    [drobna_vydani] => 0
                    [mzdy] => 0
                    [postovne] => 0
                    [cestovne] => 0
                    [odvod_kb] => 0
                )

        )

Max_admin 12 Sep, 2014
ok, please try to edit the $keys and $values lines to be in this format:
\GCore\Libs\Arr::getVal(\GCore\Libs\Arr::getVal($rows, explode(".", "[n].zakladni")), explode(".", "datum"));
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
admin_wiky 12 Sep, 2014
I did it, but same result - no data in dropdown.
I tried pr($options) and debugger box empty too😟😟
Max_admin 12 Sep, 2014
1 Likes
Please try:
\GCore\Libs\Arr::getVal(\GCore\Libs\Arr::getVal($rows, explode(".", "[n].zakladni")), explode(".", "[n].datum"));

?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
admin_wiky 15 Sep, 2014
One small problem. I want use this dropdown for filtering data and if I use the filtr then in dropdown is shown one value, but not empty value. How reset filtering?
I used
<input type="reset" value="Reset!">
or I reload the link of the CC it doesnt work - it shows filtered data only.
thx
Max_admin 16 Sep, 2014
1 Likes
You will need a button which resets the field then submits the form, this can be done using js.

For new questions I suggest a new topic, this one got huge!

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
admin_wiky 16 Sep, 2014
Hi Mix,
I have founded out many js codes, they delete options in dropdown (I see no options), but after submit it doesnt work.
Dont u have some functional code?
Max_admin 16 Sep, 2014
1 Likes
Please add a normal button (type = button) and try the following code:

jQuery("#button_id").on("click", function(){
  jQuery("#form_id").reset();
  jQuery("#form_id").submit();
});
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
admin_wiky 17 Sep, 2014
Hi Max,

it works, but different way. it return the previous value of dropdown before submit. I mean, if I change the value from 501 to 502 and click on reset, then value returns to 501.
I am not sure if u understand what I want.
I have dynamic dropdown with values 501...557 for showing the records. it works. But I need show all data after filtering.
I will describe the situation:
1. open the CC list with all data (no filtering)
2. choose the value from dropdown menu (like 501) -> submit
3. data are shown for value 501.
4. Now I need show all data but I have no option how to do it. empty value isnt in drobdown because there are dynamic values and if I click on link to the CC list then are still shown filtered data.

do u understand me?
thx
Max_admin 18 Sep, 2014
Ok, then try to add an empty value for the dropdown ? change this line:
$options = array_combine($keys, $values);

to
$options = array_merge(array('' => ''), array_combine($keys, $values));


Also I suggest we start new topics since this one is very bloated with different things now!

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
admin_wiky 03 Mar, 2015
Hi Max,

I have a problem with pagination ...I have over 1000 records and so pagination is shown, but now dynamic dropdown filtering doesnt work
Max_admin 03 Mar, 2015
Hi homepat,

The conditions and header code are executed regardless of the page loaded, how do you build the dynamic dropdown ?

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
admin_wiky 03 Mar, 2015
Hi Max,
It looks like the page limit is set in sql query, but sometimes is better load all data and then set page limit by php.

I build a dynamic dropdown with your help:
// dropdown for filtering by date season
  $keys = \GCore\Libs\Arr::getVal(\GCore\Libs\Arr::getVal($rows, explode(".", "[n].pk")), explode(".", "[n].obdobi"));
  $values = \GCore\Libs\Arr::getVal(\GCore\Libs\Arr::getVal($rows, explode(".", "[n].pk")), explode(".", "[n].obdobi"));
  array_unshift($keys, '');
  array_unshift($values, 'celé období');
  $options = array_combine($keys, $values);
  $field = array 
  (
    'name' => 'fltr[pk][obdobi]',
    'id' => '',
    'options' => 
    array (
    ),
    'empty' => '',
    'values' => 
    array (
    ),
    'label' => 
    array (
      'text' => '',
      'position' => '',
    ),
    'sublabel' => '',
    'multiple' => '0',
    'size' => '',
    'class' => '',
    'title' => '',
    'style' => 'float:left;',
    'params' => '',
    ':data-load-state' => '',
    ':data-tooltip' => '',
    'type' => 'dropdown',
    'container_id' => '1',
  );
  $field["options"] = $options;
  echo '<div style="float:right;position:relative;">'.\GCore\Helpers\Html::formLine($field["name"], $field).'</div>';


problem is, in dropdown are shown values of first page, So I have no chance to filter by value out of first page, if u understand me.

thx
Max_admin 05 Mar, 2015
1 Likes
Ok, in this case you will need to load a full list of all records to use it in the dropdown.

<?php
\GCore\Libs\GModel::generateModel("Drop", array(
	'tablename' => "table_name",
));
$class = '\GCore\Models\Drop';
$data = $class::getInstance()->find('list', array('fields' => array('id', 'name')));
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
admin_wiky 06 Mar, 2015
Hi Max,
thank you, but I not sure how to modify original code.

I know that I have to replace 'table_name', 'fields', 'id', 'name' ... but what have to be instead of 'list'?

thank you.
Max_admin 06 Mar, 2015
"list" should stay as its, its the find type!
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
admin_wiky 09 Mar, 2015
Hi Max,
thx it works🙂
here is modified code of dropdown
// button for filtering by shop
  if (!is_numeric($user->username))
  {
      \GCore\Libs\GModel::generateModel("Drop", array('tablename' => "yjw8h_cf_data_filialka_pokladni_kniha",));
      $class = '\GCore\Models\Drop';
      $data = $class::getInstance()->find('list', array('fields' => array('filialka_id', 'filialka_id')));
      //sort($data, SORT_NUMERIC);
      $options2 = $data;
      $field2 = array 
      (
        'name' => 'fltr[filialka][filialka_id]',
        'id' => '',
        'options' => 
        array (
        ),
        'empty' => '',
        'values' => 
        array (
        ),
        'label' => 
        array (
          'text' => '',
          'position' => 'left',
        ),
        'sublabel' => '',
        'multiple' => '0',
        'size' => '',
        'class' => '',
        'title' => '',
        'style' => '',
        'params' => '',
        ':data-load-state' => '',
        ':data-tooltip' => '',
        'type' => 'dropdown',
        'container_id' => '0',
      );
      $field2["options"] = $options2;
      echo '<div style="float:right;position:relative;">'.\GCore\Helpers\Html::formLine($field2["name"], $field2).'</div>';
  }


One problem, array is unsorted and I need sort it. I try to use //sort($data, SORT_NUMERIC); but then filtering doesnt work - no data loaded.

thx
Max_admin 09 Mar, 2015
1 Likes
You can add order to find params:

$data = $class::getInstance()->find('list', array('fields' => array('filialka_id', 'filialka_id'), "order" => array("filialka_id")));


Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
admin_wiky 10 Mar, 2015
thx, it works.
One more question.
Can I combine 2 columns in values of dropdown (what is shown in dropdown list)? Now I have in DD same key and value (filialka_id) and I would like show filialka_id - city. how to do that?
Max_admin 13 Mar, 2015
Try to use this as one of the 2 fields:
CONCAT("filialka_id", "city")


If it doesn't work then try:
:CONCAT("filialka_id", "city")
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
admin_wiky 16 Mar, 2015
I forgot one thing ... I need the city column from another table .... but it is problem ....I understand that I have to do
\GCore\Libs\GModel::generateModel("Drop2", array('tablename' => "second_table",));
      $class2 = '\GCore\Models\Drop2';


but how to implement to this to use CONCAT?
$data = $class::getInstance()->find('list', array('fields' => array('filialka_id', 'filialka_id'), "order" => array("filialka_id")));
Max_admin 16 Mar, 2015
After you get the data from the 2nd table, just loop over the results and create a 3rd list from a mix of both results, that's the easiest solution.
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.