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!

How to save AND insert

rslyra 06 Mar, 2020
Hi.

I'm having difficulty to save AND insert.

I made a form that's receive a parameter ID with a number, to edit a record, or zero, to insert a new one.

If I use action is on Auto detect, works ok to edit, but don't insert.
If I use action Insert - duplicate key update, works ok to insert, but insert a new record when I tried to edit.

My ID value is passed as parameter, then I recover it with
$form->data['id']=$_REQUEST['id'];

and in the save block I use

{data:id}
healyhatman 06 Mar, 2020
Read data. Not found? Insert. Found? Update.
Max_admin 06 Mar, 2020
$form->data['id']=$_REQUEST['id'];
wrong code, you should use "insert - duplicate key update" and you should pass the id in the data provider or in the "data overrides"
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
rslyra 06 Mar, 2020
Ok, "Not found? Insert. Found? Update." This I understand, but how?

Read data is in the LOAD section and Save is in the Submit section. How to conect it?
rslyra 06 Mar, 2020
And what is right? {var:read.data.org_id} ?
healyhatman 06 Mar, 2020
Nothing stopping you putting another read data in there
rslyra 06 Mar, 2020
"Nothing stopping you putting another read data in there"

You mean ...

Load/Action
---block [read data]
end Load



Submit/Action
---block [read data]
------on Found
---------block [Save Data] (set to update)
------on NotFound
---------block [Save Data] (set to insert)
end Submit
rslyra 06 Mar, 2020
Ok, I did, but only works for insert.

I think my mistake is defining the value of the ID on update clause.


I have this value in two places: first in parameter ID and second on the DATA record. I tried {var:id} and {var:read.data.org_id}

In CHF4 I used to create a hidden field. Is this still necessary?

CH01.png


CH02.png
healyhatman 06 Mar, 2020
If you are getting it from a url parameter it's {data not var
Max_admin 08 Mar, 2020
if you just use the "insert - duplicate key update" "write action" then it will insert if the "primary key" value is not available in the table, otherwise it will update!
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
rslyra 08 Mar, 2020
OK, but what is "value not avaiable"?

I have a WHERE clause, with a value. I expect that when this value is ZERO or NULL, it will insert, but this is not the case.

How I show to CHF6 tha the value is not avaiable?
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