Buy Now
Sign in

Populate text fields from DB based on data in other text fields

Elitakey , January 10 at 15:41
E
Elitakey

Hello, Could somebody give the direction where to look or how to do following:

I have 5 text fields in my CF6 form:

Name
Surname
Birthdate
Code
Number

That match DB table 'DBsaraksts' column names.

I need the code? or some CF6 action/event or whatever (I cannot figure out) to look for the three first fields to mach in DB table and return the Code and Number from the row.

I have managed to perform DB read action and got the array of all DB table records:

Array
(
[read_data4] => Array
(
[log] => Array
(
[0] => SELECT `Kodi`.`Name` AS `Kodi.Name`, `Kodi`.`Surname` AS `Kodi.Surname`, `Kodi`.`Birthdate` AS `Kodi.Birthdate`, `Kodi`.`Code` AS `Kodi.Code`, `Kodi`.`Number` AS `Kodi.Number` FROM `DBsaraksts` AS `Kodi` LIMIT 10000;
)

[var] => Array
(
[Kodi] => Array
(
[Name] => Janis
[Surname] => Berzins
[Birthdate] => 21.01.2001.
[Code] => 23465768
[Number] => JB2345
)

)

)

)

What next? Some PHP code? Where? Or jQuery? How?
Thank you in advance -
Elita

admin

Hi Elita,

What do you want to do with the data ? how should the form work ? user fills the fields then submits the form, the data is loaded, then ?

Best regards

Max
If your main question got answered then please mark the answer using the button!

E
Elitakey

Hi, Max,
I need that this way - when user fills in first three text fields - Name, Surname, Birthdate - these fields should be compared with the data in the DB table, found data for two remaining fields Code, Number and all together should be saved in the new database table. All fields Names are the same as DB column names.

admin

Hi Elita,

You just need to use the "where conditions" and match the fields to the form input using the {data:form_field_name} shortcode:

				table_field:{data:form_field}
				


Best regards

Max
If your main question got answered then please mark the answer using the button!

E
Elitakey

Hi, Max, still have "black hole" somewhere :) sorry.
So, I read data from the DB as you wrote - set the DB Read with the conditions where Name:{data:Name}, etc. That I understand and already did.
Debugger shows that correct data has been retrieved.
But HOW can I get Code and Number fields populated???
Tried to put the value in Designer section like {var:read_data36.Number}, but nothing happens.
Should I put custom code somewhere or custom event that renders that data? Or custom DB save action that take the data from DB read and Save to the nev database?

admin

Hi Elita,

I'm not sure how your form works, when do you execute the "Read data" ? before or after the form is sent ?

The syntax to get the value from the read data is {var:read_data36.MODEL_NAME.Number}, but this will not return any value if the read data did not run already, it can be used in the "Value" setting of your field!

Best regards

Max
If your main question got answered then please mark the answer using the button!