CF8 Edit a previous form entry stored in a database table

ralphg 17 Nov, 2024

Hello,

I want to define a form to save the entered data to a table in the database. But when the user wants to edit the previous data he must be able to change this. I I added the following blocks:

  1. Read data block (on load, First matching record) with a behavior 'data merge'
  2. Save data block (on Submit) Data Source {data:} with behaviors 'Table Fields' and then the allowed fields. 

When the user enters the form data a record is added but when the user changes the form data for a second time another record is added. This is not wat I want. The previous record must be updated or the last added record must be read during the load from the form. How can I configure this?

Best regards,

Ralph Gielkens.

Max_admin 17 Nov, 2024

you need to define the WHERE statement of your Read Data, it must read the previous user's record, do you have a table column for the user id ? you should have one

Same for "Save data", you need to have a WEHRE to update, so if you want to save a new record sometimes or update other times then you will need 2 Save Data actions in a switcher, the switcher will check if the Read Data returned a record or not

Your WHERE in both actions will look like this:

user_id = {user:id} // user_id is the table column where you store the user's id

and your Event Switcher "Value" will be {var:read_data_name.user_id}, replace "read_data_name" with the name of your read data action

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
ralphg 02 Dec, 2024

Hello Max, 

I'm trying to understand what you are saying but I can't get ik to work. How do I add 2 save actions in a switcher? I can't drag and drop actions to it. I only can add behaviors and event list to it. I added on load a read Data CF8 Edit a previous form entry stored in a database table image 1

and on Submit a save Data and an event switcher

CF8 Edit a previous form entry stored in a database table image 2

CF8 Edit a previous form entry stored in a database table image 3

What am I doing wrong?

Best regards,Ralph.

Max_admin 03 Dec, 2024

actually you do not need a switcher,use 2 Save Data actions, one for Insert and one for update, and control them using the "Run Conditions" behavior in each one, for the one to insert:

CF8 Edit a previous form entry stored in a database table image 4

for the one to update you should make the Comparator "Is NOT Empty"

*Alternatively you could have another Read Data in the "submit" and place the Insert in "Record not found" of Read Data, and the Update in the "Record found" of Read data

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Max_admin 10 Dec, 2024
Answer

Hi ralphg

The new v8.0.32 update has a new Save Data behavior called "Where Conditions", you can control if the conditions will run (update) or not (insert), that means you can have just one Save Data action, the condition will be just like my latest post image, but in the "Where Conditions" not "Run Conditions"

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
You need to login to be able to post a reply.

VPS & Email Hosting 20% discount
hostinger