Forums

CF8 how to use save data action to update a record

riccardoc 10 Apr, 2024
Hello, I'm trying to use ChronoForms V8. I've set up a test form that reads a record from the aaa_test_cf table, which contains the fields id - campo1 - campo2 - campo3. I have 4 textareas with the same names as the fields that take values from the first record of the table. On submit, I added the save data action, and in Behaviors, I added:

modify data source
id={data:id}
campo1={data:campo1}
campo2={data:campo2}
campo3={data:campo3}
Primary key
id
Table fields
campo1 campo2 campo3
When I save the record, I get the error "Duplicate entry '11' for key 'aaa_test_cf.PRIMARY'". If I remove id={data:id}, it saves a new record with a sequential id instead.


How can I force an update of the record?
Max_admin 12 Apr, 2024
Answer
1 Likes
Add a WHERE statement to do an UPDATE:

id={data.quote:id}
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
riccardoc 12 Apr, 2024
1 Likes
Thank you, Max, it works perfectly.

I want to report an issue I've encountered with data loading. As you can see in the screenshots, when I load the "id" field, the system correctly reads the value (1), but in the text field, regardless of the read value, it writes "11". I tried changing the name in the table from "id" to "idx" (obviously resetting all the form references), and everything works correctly. I don't know if this is a bug or if I'm missing something.
Screenshot 2024-04-12 alle 10.19.31 copia.png
Max_admin 12 Apr, 2024
id is the name of the id column in the forms table too, so I think there is a conflict

Did you know that you can use the "Merge data" behavior in the "Read data" to set your field values and avoid having to use the "Default value" for every field ?
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
riccardoc 12 Apr, 2024
1 Likes
"Merge data" is perfect! works great to me.

You are right about the form id, 11 was the id of the form and if I duplicate it it takes the new id, so I do not have to use "id" in the tables.

Thanks Max.
Max_admin 12 Apr, 2024
You are welcome
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
You need to login to be able to post a reply.