I've read the FAQ page at https://www.chronoengine.com/faqs/70-cfv5/5219-how-to-load-record-data-from-a-database-table-into-your-form.html.
But it doesn't cover much. It only covers setting up the DB Read event. I've set the table name, field, and conditions as explained in that article. My field name, 'cb_com_company', is identical to the dropdown field name in the 'design' area. But it doesn't mention what you should put in for the field 'options' (if anything), or anything about setting up the field.
The FAQ article didn't mention what kind of field, so maybe this is not possible for loading options into a dropdown field?
On the conditions, I first assumed these were database conditions and only wanted it to pull data from the field, 'cb_com_company' when the field in the column 'cb_accounttype' was equal to 'Company'. So I wrote it like:
<?php
return array('cb_accounttype' => 'Company');
?>
Then after reading the instructions on that FAQ page over and over, I decided maybe that was what told the event where to place the fields, so I re-wrote it to:
<?php
return array("cb_com_company" => form->data("cb_com_company"))
?>
The form field and the database field have the exact same name. But this doesn't make nearly as much sense to me as the way I wrote it first.
Any help with this would be appreciated. Or maybe the link to where it says, "For more examples and more advanced queries please check this FAQ", on that FAQ page I mentioned above (the link is broken).
Thanks!
But it doesn't cover much. It only covers setting up the DB Read event. I've set the table name, field, and conditions as explained in that article. My field name, 'cb_com_company', is identical to the dropdown field name in the 'design' area. But it doesn't mention what you should put in for the field 'options' (if anything), or anything about setting up the field.
The FAQ article didn't mention what kind of field, so maybe this is not possible for loading options into a dropdown field?
On the conditions, I first assumed these were database conditions and only wanted it to pull data from the field, 'cb_com_company' when the field in the column 'cb_accounttype' was equal to 'Company'. So I wrote it like:
<?php
return array('cb_accounttype' => 'Company');
?>
Then after reading the instructions on that FAQ page over and over, I decided maybe that was what told the event where to place the fields, so I re-wrote it to:
<?php
return array("cb_com_company" => form->data("cb_com_company"))
?>
The form field and the database field have the exact same name. But this doesn't make nearly as much sense to me as the way I wrote it first.
Any help with this would be appreciated. Or maybe the link to where it says, "For more examples and more advanced queries please check this FAQ", on that FAQ page I mentioned above (the link is broken).
Thanks!
Hello tim92109,
I'm not a Chrono professional, but after checking your new post, I think that the following links may help:
How to load record data from a database table into your form
How do I save form data to a database table?
My form data isn't saving to the database correctly
My CFv5 form data isn't saving to the database correctly
P.S: I'm just an automated service😉
I'm not a Chrono professional, but after checking your new post, I think that the following links may help:
How to load record data from a database table into your form
How do I save form data to a database table?
My form data isn't saving to the database correctly
My CFv5 form data isn't saving to the database correctly
P.S: I'm just an automated service😉
Thanks for trying, but the first link is the same one I mentioned didn't cover all the directions. And the second 2 are regarding saving data to the database... nothing to do with populating options on a field with data from the database. But thanks.
Thanks for the additional page, Bob! I wasn't planning on working on this project today, but I got excited and thought that would get me through it. But my dropdown still isn't showing any data.
There are a lot of things that aren't addressed so maybe I'm making a mistake on one of those.
First, it says create a DB Read onload event. It doesn't say if you should put anything in the 'on success' or 'on failure' areas of it, so I left those blank. I also tried putting the 'load html' in the 'on success' and that produced the same results.
On DB Read Event:
I did not enable the model ID because there is no 'model ID' field on the next step (the dynamic data tab on the element) unlike the instructions says there is. And it said the model ID was optional I believe. I entered the table and 2 fields (id,cb_com_company), but ignored the 'order', 'group', and 'conditions' fields. I will have conditions, but I want to get it working first.
On the form element General tab:
I made the field ID exactly the same as the first database field (cb_com_company). Also made it the same as the database table, just in case that made a difference. I think I read it should be on one of those FAQ pages). I didn't really change anything else on this tab except the label and left the 'options' blank since it was not mentioned in the directions.
On the form element Dynamic Data tab:
I did not enter a data path because it was not mentioned and I don't believe there is one since that usually pertains to the path of form field data.
I put the first field from the database (id) in the value key and the second (cb_com_company) in the text key.
Probably doesn't matter, but that field is blank on the first record in the table. I have the DB Read set to 'multi read' though, so I don't see why the others wouldn't show.
Thanks again, in advance.
There are a lot of things that aren't addressed so maybe I'm making a mistake on one of those.
First, it says create a DB Read onload event. It doesn't say if you should put anything in the 'on success' or 'on failure' areas of it, so I left those blank. I also tried putting the 'load html' in the 'on success' and that produced the same results.
On DB Read Event:
I did not enable the model ID because there is no 'model ID' field on the next step (the dynamic data tab on the element) unlike the instructions says there is. And it said the model ID was optional I believe. I entered the table and 2 fields (id,cb_com_company), but ignored the 'order', 'group', and 'conditions' fields. I will have conditions, but I want to get it working first.
On the form element General tab:
I made the field ID exactly the same as the first database field (cb_com_company). Also made it the same as the database table, just in case that made a difference. I think I read it should be on one of those FAQ pages). I didn't really change anything else on this tab except the label and left the 'options' blank since it was not mentioned in the directions.
On the form element Dynamic Data tab:
I did not enter a data path because it was not mentioned and I don't believe there is one since that usually pertains to the path of form field data.
I put the first field from the database (id) in the value key and the second (cb_com_company) in the text key.
Probably doesn't matter, but that field is blank on the first record in the table. I have the DB Read set to 'multi read' though, so I don't see why the others wouldn't show.
Thanks again, in advance.
Hi tim92109,
The On Success and On Fail boxes are triggered when the DB Read returns results / or doesn't. Generally you can ignore the On Success box and place those actions after the DB Read as you have. You can use the On Fail if you want to do 'something' when no results are found.
You do need to set a Model ID in the DB Read - in the Dynamic Data tab this now goes into the Data Path box and tells ChronoForms where to look for the data in the $form->data[''] array.
Bob
The On Success and On Fail boxes are triggered when the DB Read returns results / or doesn't. Generally you can ignore the On Success box and place those actions after the DB Read as you have. You can use the On Fail if you want to do 'something' when no results are found.
You do need to set a Model ID in the DB Read - in the Dynamic Data tab this now goes into the Data Path box and tells ChronoForms where to look for the data in the $form->data[''] array.
Bob
Thanks for the help. It still didn't work, so I continued experimenting and got it working. Apparently, the 'ever so complex' data path under the dynamic data tab isn't so complex. Here I've been using all kinds of possibilities similar to the examples I found. I came to find out it was nothing more than the model ID. I guess this used to be simpler in V4, but the field was changed from 'model ID' to 'data path'. But it works... so I'm happy. Thanks.
Hi there,
I have a question with the DB Read.
I still haven't figured out how to get the values to be shown in the form fields.
So, on the Setup, before the HTML render, you set a DB Read. (for example a table with user-info).
- You select your table name
- Enable Model ID YES
- Set Model ID to "data"
After, you create a form and you have field "name" and "email". Their ID is "name" and "email", similar to the values on the table Users.
My question:
How do I link the name-value (that can be found in the table Users) so that in the field "name", the name-value appears.
Do I set "Field Value" (an option on a "Text Box") to
$form->data['name'] ?
Kind regards,
JMN
I have a question with the DB Read.
I still haven't figured out how to get the values to be shown in the form fields.
So, on the Setup, before the HTML render, you set a DB Read. (for example a table with user-info).
- You select your table name
- Enable Model ID YES
- Set Model ID to "data"
After, you create a form and you have field "name" and "email". Their ID is "name" and "email", similar to the values on the table Users.
My question:
How do I link the name-value (that can be found in the table Users) so that in the field "name", the name-value appears.
Do I set "Field Value" (an option on a "Text Box") to
$form->data['name'] ?
Kind regards,
JMN
This topic is locked and no more replies can be posted.