Where do I place the db read?
right now my setup sheet is as follows:
in on load;
--autocompleter
--db read
--html render form
in on ajax_province
--custom code
my code:
Unfortunately it does not work
right now my setup sheet is as follows:
in on load;
--autocompleter
--db read
--html render form
in on ajax_province
--custom code
my code:
<?php
$countries = array();
if ( !$form->data['Data'] || count($form->data['Data']) < 1 ) {
// no result was found
$countries[] = 'Nessun comune in lista';
} else {
foreach ( $form->data['Data'] as $d ) {
$countries[$d['id']] = $d['id'];
$countries[$d['name']] = $d['name'];
}
}
foreach($countries as $country){
if(!empty($form->data['tag']) AND stripos($country, $form->data['tag']) === false){
continue;
}
$json[] = array('id' => $country, 'text' => $country);
}
echo json_encode($json);
?>
Unfortunately it does not work
Hi giusebos,
The DB Read action has to be in the same event - ajax_province - as the custom code to use the data being read. And the DB Read must be before the Custom Code action.
Bob
The DB Read action has to be in the same event - ajax_province - as the custom code to use the data being read. And the DB Read must be before the Custom Code action.
Bob
Hi giusebos,
That looks correct. What is the problem?
In you check the Network tab in your browser Web Developer tools you should be able to see what is being returned from the Ajax query.
Bob
That looks correct. What is the problem?
In you check the Network tab in your browser Web Developer tools you should be able to see what is being returned from the Ajax query.
Bob
ok, I had a problem of adaptation of the code to my table
correct string $json[] = array('id' => $una_regione, 'text' => $una_regione);
wrong string $json[] = array('idregione' => $una_regione, 'text' => $una_regione);
<?php
$lista_regioni = array();
if ( !$form->data['Datareg'] || count($form->data['Datareg']) < 1 ) {
// no result was found
$lista_regioni[] = 'Nessuna regione nella lista';
} else {
foreach ( $form->data['Datareg'] as $d ) {
$lista_regioni[$d['idRegione']] = $d['idRegione'];
$lista_regioni[$d['nomeRegione']] = $d['nomeRegione'];
}
}
foreach($lista_regioni as $una_regione){
if(!empty($form->data['tag']) AND stripos($una_regione, $form->data['tag']) === false){
continue;
}
$json[] = array('id' => $una_regione, 'text' => $una_regione);
}
echo json_encode($json);
?>
correct string $json[] = array('id' => $una_regione, 'text' => $una_regione);
wrong string $json[] = array('idregione' => $una_regione, 'text' => $una_regione);
Hi giusebos,
You could possibly do this in the Ajax code box if you have the data to save. Or you could add custom code to let the User add the data themselves
BUT my experience is that if you let users add new data like this you can get a lot of 'junk' or near-duplicate entries.
Bob
You could possibly do this in the Ajax code box if you have the data to save. Or you could add custom code to let the User add the data themselves
BUT my experience is that if you let users add new data like this you can get a lot of 'junk' or near-duplicate entries.
Bob
This topic is locked and no more replies can be posted.