Populate form from DB

amatenator 28 Mar, 2019
Hi all,

I have created a form where users enters his data and it correctly saves it to the DB.
Now I'm trying to do an equivalent one to first read the DB, find the record and populate the form.

The systems seems to read well the DB but I don't know how to populate the form.
First action of Setup is Read Data with:
Condition: email:{user:email} (is seems to find the record)
Then I have the following data settings

In the load section I have also this Display Form action:

I don't know what I am missing.

healyhatman 28 Mar, 2019
You are missing putting {var:read_data#.model} in your "data source" field. Replace read_data# with the proper number of your read data action and model with your read data model. Your form field names will have to match.
amatenator 29 Mar, 2019
By "data source" you mean the "data provider" field in the Display form action?

Is there any tutorial on this. I have searched on line but I can not find anything for Chronoform v6.

GreyHead 29 Mar, 2019
Hi amentator,

There is some info on this in the CFv6 manual - see page 10. You can get the manual here

amatenator 01 Apr, 2019

I might be doing something wrong because I can't get my form to be populated. I have tried to leave it very simple.

In the setup I have first action ReadDB as following:

Then I have a Display Form where the Data Provider I have: {var:read_data4}

The name of the fields in the table DB are exactly the same as those from the form.

I don't know what I am missing...

healyhatman 01 Apr, 2019
Like I said, {var:read_data#.model}
amatenator 01 Apr, 2019
I have also tried {var:read_data4.model} in Data provider but still not working.
healyhatman 01 Apr, 2019
Well replace model with the name of your model
amatenator 01 Apr, 2019
oops, true.

Thanks. It works now.
tshirley 16 Aug, 2019

I am sorry to open this again. I have also this problem - I read data, it does not populate fields in the form.

I have CF6 Version 6.1.4.

I cannot find an action for Display Form, only for Display Layout, and Display Layout does not have all the form attributes such as Data Provider. So how is it done?

healyhatman 16 Aug, 2019
Set form to custom, put all fields in a "form area"
healyhatman 16 Aug, 2019
Or just put the {var:readdata.model.field} in each field. Much easier
tshirley 16 Aug, 2019
Thank you, that solves the problem. Although I have used CF for several years I have been using an API to an external DB in bespoke PHP. This was my first attempt at it using Read Data and Save Data actions.

I must admit I was expecting a more "out of the box" solution to what I expect is a very common use case for forms generator products. Not your problem of course, I am just making a general comment.

Thanks again for your help.

shahabpk 17 Aug, 2019
I am facing a problem when reloading date field to CF form. My form Display Date in DD/MM/YYYY format but save to database in standard YYYY-MM-DD sql format. When I read the data from table to populate in the date field it is not displyimg the date correctly. How can we reload the date in DD/MM/YYYY format in CF form?
healyhatman 17 Aug, 2019
shahabpk 20 Aug, 2019
Thank you healyhatman
shahabpk 21 Aug, 2019
Hi healyhatman
I tried to apply the above solution to reload date from last created record in to a date field using
But it ended up in an error 0

DateTime::__construct(): Failed to parse time string ((var:read_data24.LastRecord.duty_date) at position 0 ((): The timezone could not be found in the database

What could be the problem?
GreyHead 21 Aug, 2019

There's a typo - the closing ) is missing from healyhatman's example.

shahabpk 22 Aug, 2019
I added the closing ) to the example. Now The error is not generated , instead it populates the current date instead of the date in the read_data variable. I attached the screenshot of the problem along with the debug report of the read data.
1. I have a read_data action named read_data24 to get the duty _date value from last saved record.
2. The duty_date field is formatted for DD/MM/YYYY but saved to YYYY-MM-DD format
3. Aadded {date:d/m/Y$(var:read_data24.LastRecord.duty_date)} in duty_date 'value' field
4. But when form loaded the debug report shows the read data is correct but Date field is loaded with current date !
5. Also when I try to save the data , It saves the date in DD/MM/YYYY format in database instead of YYYY-MM-DD

This topic is locked and no more replies can be posted.