You are on page 1of 3

How to load one row from a DB table into your form

In the last tutorial we have created a form which saves some fields data into a connected database table, but what if we want to load some record data from that table into our form ? Let's see how this can be done: 1. We are going to use the same form which we have used in our last tutorial for db save. 2. Open the form for editing in the wizard using the Wizard edit link in the forms manager. 3. Drag a DB Record Loader action to the On Load Event of the form, make sure its placed BEFORE the Show HTML action.

4. Let's configure the new DBRL (DB Record Loader) action. 5. First, we need to decide how are we going to load the record from the db table, in this tutorial, we are going to pass the value of the cf_uid field into the form url to load the corresponding record from the table, since the cf_uid is unique per record then this should be ok, so, lets write cf_uid in the DB Field parameter, then let's select our table (same table from the last tutorial or whatever table the data is stored in). 6. We assumed in our scenario that we are going to pass the cf_uid field value in the form URL, but under which parameter name that field value will be passed ? Say we are going to call it token, Chronoforms Tutorial ChronoEngine.com

example:
index.php?option=com_chronoforms&chronoform=user_details&token=ff2119500f1a4ec2318c210bf681b0fe

Then, let's write token in the Request Param field. 7. And because we need to load saved fields data into our form fields (pay attention that the form fields names should match the table columns names) then we should set the Load Fields setting to Yes.

8. Although there are some other settings to configure, but they are not needed in this scenario, the WHERE box can be used to write a custom query which should be more flexible than using a single DB Field and value pair, and the Model ID settings should be helpful when loading the data of multiple tables into 1 form with different fields names. 9. Click Apply then close the popup and click Save. 10. Let's test our form as usual using the default url (without the token param), it should be empty as before.

Chronoforms Tutorial ChronoEngine.com

11. Then with the token param in the link, we can see the data of the corresponding record, yay!! :)
index.php?option=com_chronoforms&chronoform=user_details&token=ff2119500f1a4ec2318c210bf681b0fe

12. Some may ask, what if I clicked submit button now ? What would happen ? Indeed, a new db record will be created, but of course many would like to update the loaded record, in this case, you will have to go back to the wizard edit and drag a Hidden field to your form and edit its name to cf_id which is the Primary Key of the connected table, only then the loaded record will be updated when the form is submitted instead of creating a new one. 13. One final note is that you should be able to grab the data loaded through multiple methods, like {field_name} in your form code, so for example, if you have this text in your form code: {cf_uid} or {profession} then it would be replaced by the value of the same field from the record loaded. Also, if some Model ID was used in the action settings, then all the record data would be placed under that Model ID in the $form->data array, which is accessible in PHP code only of course.

Chronoforms Tutorial ChronoEngine.com

You might also like