Forums

Populate form with data from DB

Vmad 29 Jun, 2014
Hi,
I would like to populate my fields form with data from a DB which a iD column is the same input searched by a user .I will try to explain better: the user insert the ID of a patient and after a search in the DB if the ID already exixts then the data should populate the form otherwise the fields of the form should remain blank for the input.

How should I use event switch and DB read?

Thank you in advance.
GreyHead 30 Jun, 2014
Hi Vmad,

The simplest way is to use two linked forms. The first one accepts an ID (or it could show a list of IDs). The second uses a DB Read to load the matching record. You can use the pink On NotFound event to handle the Not Found event.

Bob
Vmad 30 Jun, 2014
Thank you Bob,

I think this would be perfect ! I would like to use a event switch with this code to find data in db

<?php

$verifica=$form->data['id_paziente'];
$database = JFactory::getDBO();
$controllo = "SELECT * from fimp_chronoengine_chronoforms_datatable_paziente where  id_paziente = '$verifica'";
$database->setQuery($controllo);
$risultato = $database->loadAssocList();
if(count($risultato)){

      return fail;
 }
 else {
      return success;
 }

?>


and I find the record and return success(with db read inside), but how to use db read? how to load the data of that patient? can you help me please
Max_admin 30 Jun, 2014
The DB Read has 2 events, found and not found, and here is how you can use your own WHERE (conditions):
http://www.chronoengine.com/faqs/72-ccv5/5215-how-do-i-build-a-where-statement-in-ccv5.html

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.