Hello!
I must have a problem of syntaxe in my code.
I use JEvents and so I've got two table linked : a principal table (gen) which store an event and the categorie attached to it, and the detail table (det) which store the name of the event, the date and all sorts of details.
They are linked by an id : gen.detail_id=det.evdet_id
What I want is a form where the user can choose a categorie of event with a drop down then with a dynamic drop down using an ajax event, a second drop down let the user choose an event from all of the event of the chosen categorie.
I've find the way to have a dynamic drop down based on the table gen with the detail_id in value and text, but what I need is a dynamic drop down with the detail_id in value and the name of the event (store as summary in det).
See the backup attached below:
[attachment=0]creation_cr1.zip[/attachment]
My question is : can I use a simple custom code as shown in the tutorial about the double drop down with ajax (see below) with the correct syntaxe of the data
Changing :
'articles' -> 'gen'
'id' -> 'detail_id'
'title' -> 'summary'
If I do so (replace 'summary' or even 'det.summary' instead of title), the dynamic drop down works but with a bug : I've got the right number of lines in the drop down selection but they are blank, without the summary.
PS : If I replace 'title' with 'detail_id', the drop down works (but it's not really useful to have an event called by its id number)
I have tried the link between the two table (gen and det) and it works, so I think it's really a problem of syntaxe in my code.
Or do I need something more complicated?
I must have a problem of syntaxe in my code.
I use JEvents and so I've got two table linked : a principal table (gen) which store an event and the categorie attached to it, and the detail table (det) which store the name of the event, the date and all sorts of details.
They are linked by an id : gen.detail_id=det.evdet_id
What I want is a form where the user can choose a categorie of event with a drop down then with a dynamic drop down using an ajax event, a second drop down let the user choose an event from all of the event of the chosen categorie.
I've find the way to have a dynamic drop down based on the table gen with the detail_id in value and text, but what I need is a dynamic drop down with the detail_id in value and the name of the event (store as summary in det).
See the backup attached below:
[attachment=0]creation_cr1.zip[/attachment]
My question is : can I use a simple custom code as shown in the tutorial about the double drop down with ajax (see below) with the correct syntaxe of the data
<?php
$results = array();
$results[] = '=??';
foreach ( $form->data['articles'] as $v ) {
$results[] = $v['id'].'='.$v['title'];
}
$results = implode("\n", $results);
echo $results;
$mainframe =& JFactory::getApplication();
$mainframe->close();
?>
Changing :
'articles' -> 'gen'
'id' -> 'detail_id'
'title' -> 'summary'
If I do so (replace 'summary' or even 'det.summary' instead of title), the dynamic drop down works but with a bug : I've got the right number of lines in the drop down selection but they are blank, without the summary.
PS : If I replace 'title' with 'detail_id', the drop down works (but it's not really useful to have an event called by its id number)
I have tried the link between the two table (gen and det) and it works, so I think it's really a problem of syntaxe in my code.
Or do I need something more complicated?
Hi Flo,
So what code are you using in the Ajax event?
I have to say that I don't really follow all of your explanation here :-(
Bob
So what code are you using in the Ajax event?
I have to say that I don't really follow all of your explanation here :-(
Bob
Hello!
I'll try to explain with more details...
[attachment=2]Preview.PNG[/attachment]
[attachment=1]Events.PNG[/attachment]
[attachment=0]DB.PNG[/attachment]
First drop-down:
General
Label Text : Choisir l'activité
Field Name : name_cat
Field id : cat
Dynamic data
Enable : yes
Data path : categories
Value key : id
Text key : title
Second drop down:
General
Label Text : Choisir la sortie
Field Name : sortie
Field id : events
Dynamic data
Enable : yes
DB multi record loader (0):
Basic
Table : #_categories
Model ID : categories
Fields : id,title
Advanced
Load data : yes
Enable association : no
Dynamic drop down (2):
Source Dropdown ID : cat
Target Dropdown ID : events
Use Ajax : yes
AJAX Event name : ajax
Extra option : x
DB multi record loader (6):
Basic
Table : #_jevents_vevdetail
Model ID : det
Fields : summary,dtstart
Advanced
Load data : no
Enable association : no
Join rule : `gen`.`detail_id`=`det`.`evdet_id`
Associated model : gen
DB multi record loader (3):
Basic
DB field : catid
Table : #_jevents_vevent
Request param : name_cat
Model ID : gen
Fields : detail_id
Advanced
Load data : yes
Enable association : yes
Associated model : det
Group model : no
Custom code (4):
I'll try to explain with more details...
[attachment=2]Preview.PNG[/attachment]
[attachment=1]Events.PNG[/attachment]
[attachment=0]DB.PNG[/attachment]
First drop-down:
General
Label Text : Choisir l'activité
Field Name : name_cat
Field id : cat
Dynamic data
Enable : yes
Data path : categories
Value key : id
Text key : title
Second drop down:
General
Label Text : Choisir la sortie
Field Name : sortie
Field id : events
Dynamic data
Enable : yes
DB multi record loader (0):
Basic
Table : #_categories
Model ID : categories
Fields : id,title
Advanced
Load data : yes
Enable association : no
Dynamic drop down (2):
Source Dropdown ID : cat
Target Dropdown ID : events
Use Ajax : yes
AJAX Event name : ajax
Extra option : x
DB multi record loader (6):
Basic
Table : #_jevents_vevdetail
Model ID : det
Fields : summary,dtstart
Advanced
Load data : no
Enable association : no
Join rule : `gen`.`detail_id`=`det`.`evdet_id`
Associated model : gen
DB multi record loader (3):
Basic
DB field : catid
Table : #_jevents_vevent
Request param : name_cat
Model ID : gen
Fields : detail_id
Advanced
Load data : yes
Enable association : yes
Associated model : det
Group model : no
Custom code (4):
<?php
$results = array();
$results[] = '=??';
foreach ( $form->data['gen'] as $v ) {
$results[] = $v['detail_id'].'='.$v['summary'].' - '.$v['dtstart'];
}
$results = implode("\n", $results);
echo $results;
$mainframe =& JFactory::getApplication();
$mainframe->close();
?>
...Next
And the result :
[attachment=0]Test form.PNG[/attachment]
I've only got one event from the category 'Randonnée' and you can see that there is a '-'
My question is : what can I do to have the summary and if it's possible the dtstart, and not a blank?
Thanks
Flo
And the result :
[attachment=0]Test form.PNG[/attachment]
I've only got one event from the category 'Randonnée' and you can see that there is a '-'
My question is : what can I do to have the summary and if it's possible the dtstart, and not a blank?
Thanks
Flo
Hi!
I have found (in fact it's my little brother) the solution:
Here the result :
[attachment=0]Test form ok.PNG[/attachment]
Next problem : the dtstart is not really explicit in this format (it's the 21/12/2012 in explicit format).
Maybe I could use the function strftime(), but I don't know if it's work with CF and how to use it...
Edit : Found!
I've made some progress in php🙂
Thanks Bob, even if you haven't done something tangible this time, it's make me think about my problem when I'm trying to explain it.
Until the next question...
Florence
I have found (in fact it's my little brother) the solution:
<?php
$results = array();
$results[] = '=??';
foreach ( $form->data['gen'] as $v ) {
$results[] = $v['detail_id'].'='.$v['det']['summary'].' - '.$v['det']['dtstart'];
}
$results = implode("\n", $results);
echo $results;
$mainframe =& JFactory::getApplication();
$mainframe->close();
?>
Here the result :
[attachment=0]Test form ok.PNG[/attachment]
Next problem : the dtstart is not really explicit in this format (it's the 21/12/2012 in explicit format).
Maybe I could use the function strftime(), but I don't know if it's work with CF and how to use it...
Edit : Found!
<?php
$results = array();
$results[] = '=??';
foreach ( $form->data['gen'] as $v ) {
$date = $v['det']['dtstart'];
$newdate = strftime("%d/%m/%y",$date);
$results[] = $v['detail_id'].'='.$v['det']['summary'].' - '.$newdate;
}
$results = implode("\n", $results);
echo $results;
$mainframe =& JFactory::getApplication();
$mainframe->close();
?>
I've made some progress in php🙂
Thanks Bob, even if you haven't done something tangible this time, it's make me think about my problem when I'm trying to explain it.
Until the next question...
Florence
This topic is locked and no more replies can be posted.