Buy Now
Sign in

one form for edit and new - is it possible?

Elitakey , March 03 2020, 18:14
E
Elitakey 282
March 03 2020, 18:14 #391472
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
E
Elitakey 282
March 03 2020, 18:24 #391473
 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 9
March 03 2020, 22:17 #391479
Or you could (and should, really) just have two events.
Web developer at SkySpider.com.au - I DO NOT work for ChronoEngine!
Donations: paypal.me/healyhatman
Professional Work: kamron@skyspider.com.au
Custom CF / CC Plugins and Extensions: skyspider.com.au/store
E
Elitakey 282
March 04 2020, 06:11 #391483
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 9
March 04 2020, 10:27 #391487
One FORM is fine, sorry I thought you meant one EVENT
Web developer at SkySpider.com.au - I DO NOT work for ChronoEngine!
Donations: paypal.me/healyhatman
Professional Work: kamron@skyspider.com.au
Custom CF / CC Plugins and Extensions: skyspider.com.au/store
E
Elitakey 282
March 04 2020, 14:28 #391490
.... 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.