Forums

Display table data in form

kkurtz 06 Sep, 2017
I have a table of golf courses and I need to make changes to the table data. I have a form where I enter the name of the course and on submit I want it to read the database to find the matching record and then display the table data in a form so I can make changes.

I think it is reading and finding the right row in the table because the corresponding data appears in the debugger array. But I can only get the course name to display in the form fields. It won't display the other two fields.How to I get it to display the table data in the form fields?
GreyHead 06 Sep, 2017
Hi kkurz,

The column names in the table and the input names in the form need to be exactly the same for this to work.

Bob

PS It might be simpler to use a CC list to show the saved records and edit from there.
kkurtz 06 Sep, 2017
My table column names are: "adaydate", "course", and "division".
I use a form to let the user input the course name, and the name of that field is "course".
Then the field names of the second form I want to load the data into are:"adaydate", "course", and "division".
The calculus00 bot pointed me to an FAQ article (https://www.chronoengine.com/faqs/5219-how-to-load-record-data-from-a-database-table-into-your-form ) which says to put the following php code in the Where Conditions box:
<?php
return array("db_field_name" => $form->data("request_param_name"));
?>
So my Where Conditions looks like this:
Courses.course/LIKE:%{data:course}%
<?php
return array("adaydate"=> $form->data("adaydate"));
?>
Where Courses is the model used to handle the courses table.

I've tried various ways of writing the both of the parms in quotes. And nothing works.Probably haven't guessed the right combination.

The FAQ also says
"Your form fields names should match the database table fields names, and if you choose to load the data under the Model ID then your form fields names should have the Model id inside, e.g: Model[field]"

I don't understand that last part of this (underlined). Please explain.

I may still have to use CC, but I would really like to understand this in CF and make it work.
Thanks,
kkurtz
GreyHead 08 Sep, 2017
Hi kkurtz,

I think that both of those FAQs were written for CFv5 and you are using CFv6 which has different syntax for the Conditions. Please check the CFv6 manual.

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