Buy Now
Sign in

URL Link to Open Form to Edit existing record

vividal , March 08 2017
V
vividal
I am new to ChronoForms and figuring things out as I go. I have a form that successfully creates a record in a DB Table. Now I would like to edit that data in the same(similar) form. I would like to open the Form from a different page using a hyperlink. My thought is I would have a link on the webpage that points to:
www.domain.com/index.php?option=com_chronoforms5&chronoform=InfoEdit&id=4

"4" would be the id of the record I want to edit. What I can't figure out is how to load the record into the form with record I want.


I am sure this has been addressed somewhere in the forum but I have been searching for 2 hours and can't find anything that does what I am trying to do.
GreyHead
Hi vividal,

You can use a DB Read action with an entry in the Conditions box like this
<?php
return array( 'id' => $form->data['id'] );
?>

Bob

PS Using id for the primary key in the table can cause problems if there are other values of id in use e.g. article ids if the form is on an article page, better to use something different like cf_id
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
V
vividal
Thx for the pointers, but I am still missing something and your PS has led me to more questions.

1) all tables have the 'id' field. should I not be using that as my unique identifier for everything?

2) in the php statement you provided, data is the model id, correct? I am getting nothing field in on the form when I open it.
GreyHead
Hi vividal,

You can use (almost) anything you like as the name for the primary key column in a table. By default they are named id but this is not required and can sometimes cause problems so I normally use cf_id.

ChronoForms stores the data in the $form->data array if you have a Model ID set then it would be $form->data['model_id']['id']

If you add a Debugger action temporarily you can see the MySQL query that is being generated.

Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
V
vividal
OK so...I am able to read the 'id' from the url and pass it to the form but I dont think that has anything to do with the php statement you gave me. How do I actually pull the data from the table using the 'id' and publish the fields to the form? is there a document that shows how to do this in CF5. I found one for CF4 but couldnt figure out how it "maps" to CF5
GreyHead
Hi vividal ,

ChronoForms will automatically read the id from the URL and add it to the $form->data array - you then need to add the DB Read action with the Condition statement to read the matching record. The data from that will be added to the $form->data array and the values will be attached to any form inputs with matching names.

Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
V
vividal
I am still missing some piece to this puzzle. I have a DBRead OnLoad immediately after the debugger and before the HTML render. A table is selected from my DB.
Multiread:NO
Model ID:Yes
Model ID:TeamIn
Fields:id,TeamName,AgeLevel,Active
Condition:
<?php
return array( 'id' => $form->data.['id'] );
?>

I assume this is not correct as nothing loads in my TeamName field on the form. You can see what is happening here:
http://template.leagueops.com/index.php?option=com_chronoforms5&chronoform=TeamInfo-Test&id=4

Do you have any thoughts?
admin
Hi vividal,

The debugger should be after other actions, it will show you if the data is loaded or not.

Best regards,
Max
Max
If your main question got answered then please mark the answer using the button!​
​Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
V
vividal
Thank you for that adjustment. now I see the correct data being loaded into the array but i guess I dont know how to put it into the field on the form so it can be edited. and I am not sure where the [0]=>Array is coming from

Array
(
[option] => com_chronoforms5
[chronoform] => TeamInfo-Test
[id] => 4
[TeamIn] => Array
(
[0] => Array
(
[id] => 4
[TeamName] => Bulls Elite 12u
[AgeLevel] => 8
[Active] => 1
)

)

)
admin
Please set the model id to "no" since your field name does not have the model id in it, also is the multiread set to no ? because it looks like enabled according to the debug.

Best regards,
Max
Max
If your main question got answered then please mark the answer using the button!​
​Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
V
vividal
OK so it seems I have confused the multiread option. when I set it to no, it populates my form field as I would expect. thank you for the help. now I am on to seeing if I can get it to save the data after I change it.
V
vividal
can you point me to a document on how to update the record for the changes I made in my form. through the debug I see the ModelID_fieldname when I do a submit but how do i change that to table.fieldname Sorry I dont know PHP.

thx
admin
Hi vividal,

You need to have a hidden field with the name "id", then a "db save" action and that will update the existing record with the new data.

Best regards,
Max
Max
If your main question got answered then please mark the answer using the button!​
​Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
V
vividal
I do have the hidden field and the DB Save but the fields that show in the debug are the Model ID fields from the Read and not the fields for the DB.
admin
Please drag the debugger after the "db save" and post the results here so that we can check what's saved after the db save runs.

Best regards,
Max
Max
If your main question got answered then please mark the answer using the button!​
​Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
V
vividal
I figured out my issue with the Model IDs (lack of understanding on my part on how to use Models). Now I am working on the checkbox field. Just a single checkbox that I want to use to define whether a row is used in later queries. I have the type set to tinyint but I can't seem to get it to set when the record is submitted on my edit form (it works fine when I create the record).
V
vividal
I got the checkbox issue resolved. Thank you to both of you for helping me start to get a handle on this product. More to come I am sure.
M
muecke06
Hi guys,
I am currently trying to solve the same problem with chronoforms v6.
1. The Conditions box does not exist here.In the Where conditions box, this code gives an error.
2. the tables automatically created by chronoforms had the key "id" under v5, the key "aid" under v6.
3. Currently I pass in the URL "? Id = 3".Does it have to be "aid" now?
4. Config: read_data5
Model name: content
Where conditions: content.aid: {data: id}
Select Type: First Matching record
Do you have an idea what I'm doing wrong?
Best regards Steffen
M
muecke06
Hi guys,
I could solve it by now. It is certainly not the most elegant way.
Maybe there is a better solution - for me or for other users.
Would be nice to read here perhaps the most ideal way.
Best regards Steffen
healyhatman
Get rid of the spaces in the where conditions - should be {data:id} not {data: id}
You should be passing in the URL "&id=3" not "? id = 3" . Please note the '&' and the lack of spaces.
Web developer at SkySpider.com.au
I don't work for ChronoEngine but I do accept donations paypal.me/healyhatman