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}
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}
Read data. Not found? Insert. Found? Update.
$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"
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?
Read data is in the LOAD section and Save is in the Submit section. How to conect it?
Nothing stopping you putting another read data in there
"Nothing stopping you putting another read data in there"
You mean ...
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
Yes
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?

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?

If you are getting it from a url parameter it's {data not var
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!
This topic is locked and no more replies can be posted.
