good evening
with the precious help of greyhead(thank you so much)i made a form with chronoforms containing textarea fields and 4 dropdown lists and a submit button but the pb is that when i validate my form two of the 4 dropdown lists were not stored in the database i don't know why?can you help me please here is the code(html+javascript)
here is the javascript code
here is extracode1
and finally extracode2
thank you and excuse me if it is too long
with the precious help of greyhead(thank you so much)i made a form with chronoforms containing textarea fields and 4 dropdown lists and a submit button but the pb is that when i validate my form two of the 4 dropdown lists were not stored in the database i don't know why?can you help me please here is the code(html+javascript)
<?php
if ( !$mainframe->isSite() ) { return; }
$db =& JFactory::getDBO();
$query = "
SELECT *
FROM `pays`
ORDER BY `idpays`;
";
$db->setQuery($query);
$data = $db->loadObjectList();
?>
<fieldset style="border: 3px double #333399">
<legend>Pays et ville de résidence</legend>
<label>Pays: </label>
<select name="pays" id="pays">
<option value="">- - - Choisissez un pays - - -</option>
<?php
/* Construction de la première liste : on se sert du tableau PHP */
foreach($data as $d) {
echo "<option value='".$d->idpays."'>".$d->nompays."</option>";
}
?>
</select>
<!-- ICI, le secret : on met un bloc avec un id ou va s'insérer le code de
la seconde liste déroulande -->
<span id="blocvilles"></span><br />
<label for="ville"><?php echo JText::_( 'Ville' ); ?>:</label>
<?php
echo "<span id='AjaxgetVille';style='color:black'>".JText::_('Choisissez un pays SVP' )."</span>
<span id='progress_gV' style='visibility:hidden;' > Recherche . . .</span>";
?>
</fieldset>
<?php
if ( !$mainframe->isSite() ) { return; }
$db =& JFactory::getDBO();
$query = "
SELECT *
FROM `paysor`
ORDER BY `idpaysor`;
";
$db->setQuery($query);
$data = $db->loadObjectList();
?>
<fieldset style="border: 3px double #333399">
<legend>Pays et ville d'origine</legend>
<label>Pays: </label>
<select name="paysor" id="paysor" >
<option value="">- - - Choisissez un pays - - -</option>
<?php
/* Construction de la première liste : on se sert du tableau PHP */
foreach($data as $d) {
echo "<option value='".$d->idpaysor."'>".$d->nompaysor."</option>";
}
?>
</select>
<!-- ICI, le secret : on met un bloc avec un id ou va s'insérer le code de
la seconde liste déroulande -->
<span id="blocvilles2"></span><br />
<label for="villeor"><?php echo JText::_( 'Ville' ); ?>:</label>
<?php
echo "<span id='AjaxgetVilleor';style='color:black'>".JText::_('Choisissez un pays SVP' )."</span>
<span id='progress_gV' style='visibility:hidden;' > Recherche . . .</span>";
?>
</fieldset>
<br>
<input type="submit" name="ok" id="ok" value="Envoyer" />
here is the javascript code
window.addEvent('domready', function() {
$('pays').addEvent('change', function () {
var a = $('pays').value;
if ( a != null && a != '' ) {
getVille(a);
} else {
$('AjaxgetVille').setHTML("<span id='AjaxgetVille';style='color:black' >Choisissez un pays SVP</span>")
}
}) ;
});
function getVille(a){
var url = "index.php?option=com_chronocontact&chronoformname=test_form_94&task=extra&format=raw";
new Ajax(url, {
method: 'get',
onRequest: function(){
$('progress_gV').setStyle('visibility', 'visible');
},
onComplete: function(){
$('progress_gV').setStyle('visibility', 'hidden');
},
update: $('AjaxgetVille'),
data: 'idpays='+a
}).request();
};
window.addEvent('domready', function() {
$('paysor').addEvent('change', function () {
var a = $('paysor').value;
if ( a != null && a != '' ) {
getVilleor(a);
} else {
$('AjaxgetVilleor').setHTML("<span id='AjaxgetVilleor';style='color:black' >Choisissez un pays SVP</span>")
}
}) ;
});
function getVilleor(a){
var url = "index.php?option=com_chronocontact&chronoformname=test_form_94&task=extra&extraid=2&format=raw";
new Ajax(url, {
method: 'get',
onRequest: function(){
$('progress_gV').setStyle('visibility', 'visible');
},
onComplete: function(){
$('progress_gV').setStyle('visibility', 'hidden');
},
update: $('AjaxgetVilleor'),
data: 'idpaysor='+a
}).request();
};
here is extracode1
<?php
$idpays =& JRequest::getString('idpays', '', 'get');
if ( $idpays ) {
$db =& JFactory::getDBO();
$query1 = "
SELECT `idville`, `nomville`
FROM `ville`
WHERE `idpays` = '$idpays' ;
";
$db->setQuery($query1);
$data1 = $db->loadObjectList();
}
//$return = '<div>$data1: '.print_r($data1, true).'</div>';
if ( count($data1) ) {
$m1 = new stdClass();
$m1->idville = 0;
$m1->nomville = '==?==';
$data1 = array_merge(array($m1), $data1);
//$return = '<div>$data1: '.print_r($data1, true).'</div>';
$return = JHTML::_('select.genericlist', $data1, 'Ville','class="inputbox required select" size="1" ', 'idville', 'nomville', 0);
}
else {
$return = JText::_('Pays introuvable');
}
echo $return;
?>
and finally extracode2
<?php
$idpaysor =& JRequest::getString('idpaysor', '', 'get');
if ( $idpaysor ) {
$db =& JFactory::getDBO();
$query2 = "
SELECT `idvilleor`, `nomvilleor`
FROM `villeor`
WHERE `idpaysor` = '$idpaysor' ;
";
$db->setQuery($query2);
$data2 = $db->loadObjectList();
}
//$return = '<div>$data2: '.print_r($data2, true).'</div>';
if ( count($data2) ) {
$m2 = new stdClass();
$m2->idvilleor = 0;
$m2->nomvilleor = '==?==';
$data2 = array_merge(array($m2), $data2);
//$return = '<div>$data2: '.print_r($data2, true).'</div>';
$return = JHTML::_('select.genericlist', $data2, 'Villeor', 'class="inputbox required select" size="1" ', 'idvilleor', 'nomvilleor', 0);
} else {
$return = JText::_('Pays introuvable');
}
echo $return;
?>
thank you and excuse me if it is too long