Hi,
I got the ChronoForms v4 using AJAX how to doc and followed instructions modifying column names as needed. Instead of state I have a source and the counties are casestudies.
I placed the following code on a custom form element
<?php
if ( !$mainframe->isSite() ) { return; }
$db =& JFactory::getDBO();
$query = "
SELECT DISTINCT `cf_id`, `source`
FROM `#_case_studies`
GROUP BY `source`;
";
$db->setQuery($query);
$data = $db->loadObjectList();
?>
<select class="" id="source" size="1" title="" name="source">
<option value="">==??==</option>
<?php
foreach($data as $d) {
echo "<option value='".$d->cf_id."'>".$d->source."</option>";
}
?>
</select>
On the events I have a Load JS on the On Load event and I have the following code:
var cf_formname = "Test";
window.addEvent('domready', function() {
$('state').addEvent('change', function() {
var a=$('source').value;
if(a!=null && a!='') {
getCaseStudy(a);
} else {
$('ajax_getcasestudy').setHTML("<span id='ajax_getcasestudy'>Please select source</span>")
}
});
});
function getCaseStudy(a){
var url=
'index.php?option=com_chronoforms&chronoform='+cf_formname+'&event=ajax&format=raw';
new Request.HTML({
method: 'get',
url: url,
onRequest: function(){
console.log(url);
$('progress_getcasestudy').setStyle('visibility','visible');
},
onComplete: function(){
$('progress_getcasestudy').setStyle('visibility','hidden');
},
update: $('ajax_getcasestudy'),
data: {'sid' : a}
}).send();
};
And lastly I have an Ajax Event on the form with the following code
<?php
$source_id= & JRequest::getString('sid','','get');
if ($source_id){
$db=& JFactory::getDBO();
$query="
SELECT `CaseStudyName` AS `id`, `CaseStudyName`
FROM `#_case_studies`
WHERE `source` =`$source_id`
ORDER BY `CaseStudyName`;
";
$db_>setQuery($query);
$data=$db->loadObjectList();
if(count($data)){
$m=new stdClass();
$m->id=0;
$m->CaseStudyName= '==?==';
$data = array_merge(array($m), $data);
$return = JHTML::_('select.genericlist', $data, 'CaseStudyName','class="input required select" size="1", 'id', 'CaseStudyName', 0);
}else{
$return = "Sorry, we couldn't find that source";
}
} else{
$return = "Sorry, we couldn't find a source id";
}
echo $return;
$mainframe->close();
?>
When I run the form, the first dropdown gets populated with the source but that's about it, when I select any source the second drop down doesn't get populated with the case studies. HELP please any tips are welcome as I've been staring at this for far too long and I just can't figure out what is missing.
I have looked at a similar thread at http://www.chronoengine.com/forums/index.php?option=com_chronoforums&cont=posts&f=2&t=21871 and compared my code but still no luck:(
Thanks
I got the ChronoForms v4 using AJAX how to doc and followed instructions modifying column names as needed. Instead of state I have a source and the counties are casestudies.
I placed the following code on a custom form element
<?php
if ( !$mainframe->isSite() ) { return; }
$db =& JFactory::getDBO();
$query = "
SELECT DISTINCT `cf_id`, `source`
FROM `#_case_studies`
GROUP BY `source`;
";
$db->setQuery($query);
$data = $db->loadObjectList();
?>
<select class="" id="source" size="1" title="" name="source">
<option value="">==??==</option>
<?php
foreach($data as $d) {
echo "<option value='".$d->cf_id."'>".$d->source."</option>";
}
?>
</select>
On the events I have a Load JS on the On Load event and I have the following code:
var cf_formname = "Test";
window.addEvent('domready', function() {
$('state').addEvent('change', function() {
var a=$('source').value;
if(a!=null && a!='') {
getCaseStudy(a);
} else {
$('ajax_getcasestudy').setHTML("<span id='ajax_getcasestudy'>Please select source</span>")
}
});
});
function getCaseStudy(a){
var url=
'index.php?option=com_chronoforms&chronoform='+cf_formname+'&event=ajax&format=raw';
new Request.HTML({
method: 'get',
url: url,
onRequest: function(){
console.log(url);
$('progress_getcasestudy').setStyle('visibility','visible');
},
onComplete: function(){
$('progress_getcasestudy').setStyle('visibility','hidden');
},
update: $('ajax_getcasestudy'),
data: {'sid' : a}
}).send();
};
And lastly I have an Ajax Event on the form with the following code
<?php
$source_id= & JRequest::getString('sid','','get');
if ($source_id){
$db=& JFactory::getDBO();
$query="
SELECT `CaseStudyName` AS `id`, `CaseStudyName`
FROM `#_case_studies`
WHERE `source` =`$source_id`
ORDER BY `CaseStudyName`;
";
$db_>setQuery($query);
$data=$db->loadObjectList();
if(count($data)){
$m=new stdClass();
$m->id=0;
$m->CaseStudyName= '==?==';
$data = array_merge(array($m), $data);
$return = JHTML::_('select.genericlist', $data, 'CaseStudyName','class="input required select" size="1", 'id', 'CaseStudyName', 0);
}else{
$return = "Sorry, we couldn't find that source";
}
} else{
$return = "Sorry, we couldn't find a source id";
}
echo $return;
$mainframe->close();
?>
When I run the form, the first dropdown gets populated with the source but that's about it, when I select any source the second drop down doesn't get populated with the case studies. HELP please any tips are welcome as I've been staring at this for far too long and I just can't figure out what is missing.
I have looked at a similar thread at http://www.chronoengine.com/forums/index.php?option=com_chronoforums&cont=posts&f=2&t=21871 and compared my code but still no luck:(
Thanks