ChronoEngine.com homepage

Forums

Please write a review for the extension you are using on the Joomla extensions directory before posting a new question as we are being spammed by many negative reviews.

Thank you for your support!

one form for edit and new - is it possible?

Elita 03 Mar, 2020
Hello, have a question - stuck with the following dilemma:

HOW to use one form and one Event for two actions - add new record and edit existing record?
I can either add new or edit existing record😟

My steps so far:
1) Created {fn:read_submission} with condition Submission.aid={data:aid}
2) created CF6 form with
  1. Hidden field - aid
  2. defined field names so all they have one Model - Submission[Name];
  3. added field Value - {var:read_submission.Submission.Name}
3) created button that adds record - add_button with Event "edit"; URL and/or URL parameters - empty; Submit button? unchecked;
4) created link that edits existing record - submission_edit_link with Event "edit"; URL and/or URL parameters - aid={var:submissions_list.row.Submission.aid}
5) created edit event with
  1. {fn:read_submission}
  2. {view:submission_form} - this call CF6 with {chronoform/section:juridiskas-labot/load} and save Toolbar button [ step 8) ]
6) created save function {fn:save_submission} with Data provider: {data:Submission}
7) created save event with
  1. {fn:save_submission}
  2. {redirect:index}
8) created edit_toolbar_save Toolbar button with Event save; Submit button? Checked; URL and/or URL parameters - empty;

And result is as follows:
1. when I put Update condition Submission.aid={data:aid} Edit record works/ Save new record - does not;
2. If I delete that Update condition, I am able to save New record and get duplicated record on edit;

What have I missed here?

Thank you in advance-
Elita
Elita 03 Mar, 2020
Answer
Figured out - hidden field in CF6 form should be Submission[aid].

So, all the written above could be used to create add/edit functions to your existing table.

Have a great day -
Elita
healyhatman 03 Mar, 2020
Or you could (and should, really) just have two events.
Elita 04 Mar, 2020
that was my first thought, healyhatman, but then, by analyzing Demo form Max created I noticed he used only one form. I am lazy by the nature - so tried to follow his approach😀
healyhatman 04 Mar, 2020
One FORM is fine, sorry I thought you meant one EVENT
Elita 04 Mar, 2020
.... and one event. too.
I use one Save event and one form for both actions - Add new and Edit existing - you can achieve that by adding Model to the field - that I "dug out" of the Demo form Max creatded - add Model[field name] and then on save use that Model as Data provider. Very convenient.
This topic is locked and no more replies can be posted.

2Checkout.com

2CheckOut.com Inc. (Ohio, USA) is an authorized retailer for goods and services provided by ChronoEngine.com