Forums

Fill two fields, with content of third table

AntonioGraca 06 Sep, 2013
Hello Bob
Again, I need of your precious help. 😢 I've read several FAQ's and various post in the forum but I can not see how to solve my problem.
I need to fill two fields (text or dropdown), from information of a table (Source_table3) whose search condition the content of dropdown 1 (athletes, table Source_table1)and dropdown 2 (season, table Source_table2 .)
The two dropdown (1 and 2) already has a list of athletes and the seasons through the event DB MRL. Until here, so far so good. Now, how to get the information to a third table (which have the athlete, the season, the level and the club) and, automatically, fill the fields of dropdown 1 (with the level) and dropdown2 (with the club).
I think I need a third DB MRL (go to Source_table3 to bring data) and an event Dynamic Dropdown to use ajax event.
But how to connect everything?

I send the image (worth more than thousand words) to better understand my problem.

Thanks

António Graça
GreyHead 08 Sep, 2013
Hi António,

It's a bit hard to be specific as this becomes custom code quite quickly. I just added this link to your other post requesting an example of a triple drop-down. It's not hard to do but you do have to keep careful track of the state of each part of the form.

Bob
AntonioGraca 11 Sep, 2013
Hello Bob
For now, I just try a simple way to do this.
But, I'm terribly sorry, I can not understand how to fill the last two dropdown's (Escalão and Clube) from the elements (data) listed in the first two dropdown's (Nome and Época).
I'll try to explain what I have done and the doubts I have…


Elements
The next two dropdowns (Nome and Época) will provide data to search with DBML in ajax event

Dropbox Nome
General
Label Text: Nome
Field Name: nome_marcas
Field ID: source_atletas
Ps: this dropdown is linked to DBMRL, in ajax event, to list the available seasons

Dropbox Época
General
Label Text: Época
Field Name: epoca_marcas
Field ID: source_epocas
Ps: this dropdown is linked to DBMRL, in ajax event, to list the available seasons

These two dropdowns (Escalão and Clube) will receive the data searched
Dropbox Escalão
General
Label Text: Éscalão
Field Name: escalao_marcas
Field ID: target_escalao
Dynamic Data
Enable: Yes
Data Path: epoca_source_ajax
Value Key: escalao_epocas
Text Key: escalao_epocas


Dropbox Clube
General
Label Text: Clube
Field Name: clube_marcas
Field ID: target_clube
Dynamic Data
Enable: Yes
Data Path: epoca_source_ajax
Value Key: clube_epocas
Text Key: clube_epocas

Events
Order of events OnLoad
Dynamic dropdown
Dynamic dropdown
Show Html
DBMRL to list the athletes (in dropdown Nome, work ok)
DBMRL to list the season (in drop down Época, work ok)

I think it should be a unique Dynamic Dropdown ... but how to do just one Dynamic Dropdown?
Dynamic dropdown Source Athletes
Source Dropdown ID: source_atletas
Target Dropdown ID: target_escalao
Use AJAX ?: Yes
Ajax event: ajax
Extra options extension: x

Dynamic dropdown Source Season
Source Dropdown ID: source_epocas
Target Dropdown ID: target_clube
Use AJAX ?: Yes
Ajax event: ajax
Extra options extension: x



Ajax events
Order of events On Ajax
DBML
Custom Code

DBML to seek from the data in the Dropdown Nome (Name) and Dropdown Época (Season)
Table: ?__abertura_epocas
Request Param: escalao_epocas,clube_epocas // Is it necessary?
Model ID: epoca_source_ajax
Fields: escalao_epocas,clube_epocas

WHERE statement:
<span class="syntaxhtml"><span class="syntaxdefault"><?php<br />$user </span><span class="syntaxkeyword">=&</span><span class="syntaxdefault"> JFactory</span><span class="syntaxkeyword">::</span><span class="syntaxdefault">getUser</span><span class="syntaxkeyword">();<br /></span><span class="syntaxdefault">$user_id </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> $user</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">id</span><span class="syntaxkeyword">;<br /></span><span class="syntaxdefault">$epoca_select</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">$form</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">data</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'epoca_marcas'</span><span class="syntaxkeyword">]</span><span class="syntaxdefault"> <br />$atleta_select</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">$form</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">data</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'nome_marcas'</span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault">?><br /></span>`cf_user_id` = '<span class="syntaxdefault"><?php echo $user_id</span><span class="syntaxkeyword">;</span><span class="syntaxdefault"> ?></span>' AND `epoca_epocas` = ‘$epoca_select’  AND `nome_epocas`=’$atleta_select’</span>


Obs: I intend with this code to search in table? _abertura_epoca list only athletes selected in the dropdown Nome (name) and the season selected in the dropdown Épocas (season). But, the code `epoca_epocas` = ‘$epoca_select’ does not work. I try without the code AND `epoca_epocas` = ‘$epoca_select’ AND `nome_epocas`=’$atleta_select’ and does not wok to.

Costum code:
<span class="syntaxdefault"><?php<br />$results </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> array</span><span class="syntaxkeyword">();<br /></span><span class="syntaxdefault">$results</span><span class="syntaxkeyword">[]</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxstring">'Nothing'</span><span class="syntaxkeyword">;<br /></span><span class="syntaxdefault">$selected </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxstring">"selected='selected'"</span><span class="syntaxkeyword">;<br /><br /></span><span class="syntaxdefault">foreach </span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> $form</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">data</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'epoca_epocas'</span><span class="syntaxkeyword">]</span><span class="syntaxdefault"> as $v </span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">{</span><span class="syntaxdefault">  </span><span class="syntaxcomment">///This code is not correct, Im sure…<br /></span><span class="syntaxdefault">  $results</span><span class="syntaxkeyword">[]</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> $v</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'clube_epocas'</span><span class="syntaxkeyword">];<br /></span><span class="syntaxdefault">  <br /></span><span class="syntaxkeyword">}<br /></span><span class="syntaxdefault">$results </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> implode</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"\n"</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> $results</span><span class="syntaxkeyword">);<br /></span><span class="syntaxdefault">echo $results</span><span class="syntaxkeyword">;<br /><br /></span><span class="syntaxdefault">$mainframe </span><span class="syntaxkeyword">=&</span><span class="syntaxdefault"> JFactory</span><span class="syntaxkeyword">::</span><span class="syntaxdefault">getApplication</span><span class="syntaxkeyword">();<br /></span><span class="syntaxdefault">$mainframe</span><span class="syntaxkeyword">-></span><span class="syntaxdefault">close</span><span class="syntaxkeyword">();<br /></span><span class="syntaxdefault">?></span>



The result is Undefined in last two dropown box.

Please, Bob, give me same light…

Thank's for all your support

António Graça
AntonioGraca 11 Sep, 2013
I try to put this code in JS

window.addEvent('domready', function() {
  var primary, secondary;
  // replace aaa and bbb here
  primary = $('source_atletas');
  secondary = $('source_epocas');
  if ( primary.value ) {
    var load_req = new Request({
      // replace event_name and form_name in the next line
      url: 'index.php?option=com_chronoforms&chronoform=marcas_registo_corridas-Copy&format=raw&event=ajax',
      method: 'get',
      onRequest: function(){
        secondary.empty();
        new Element('option', {
          'value': '',
          'text': 'Carregando...'
        }).inject(secondary);
      },
      onSuccess: function(responseText){
        secondary.empty();
        var response_data = responseText.trim().split("\n");
        response_data.each( function(line) {
          var line_data = line.split("=");
          var selected = ( line_data[0] == secondary_value );
          new Element('option', {
            'value': line_data[0],
            'text': line_data[1],
            'selected': selected
          }).inject(secondary);
        });
        secondary.fireEvent('change');
      },
      onFailure: function(){
        secondary.empty();
        new Element('option', {'value': '', 'text': 'Loading failed.'}).inject(secondary);
      }
    });
    load_req.send(primary.get('name')+'='+primary.value);
  }
});


But the laste two dropdown return the same, Undefined

António Graça
This topic is locked and no more replies can be posted.