Is there a simple sample somehere (many of the forum links are obsolete) on how to use dhtmlxform to insert a new row in a table and then retrieving the id of that row? So that I can update a second table with a reference to that new row (foreign key).
Seems to me like a frequent use case, but I can’t find a sample for it.
Currently I’m using a dataprocessor to load and update rows one at the time with my form, that works well.
Maybe I wasn’t clear or there is no way of doing this with the dataprocessor.
I have a table A and a table B.
A has a field (let’s name it x) which is a foreign key into table B.
Users update table A through a dhtmlxgrid, works fine.
When they double-click on a cell in the table A grid representing the field x (actually an icon), a dhtmlxForm appears to show the data in table B associated to x.
This works well when x is not null and there is actually data associated to x. The Form appears and shows the proper data, it can also be updated (through a dataprocessor for that Form). Hunky dory.
Now, I would like to be able to create new entries in B through this same mean. In other words, when x is null, I would like the form to display empty fields (kind of expected in any case), upon saving the form (form.save()) I would like the contents to be inserted in table B (viz. a new row created) and the rowid for that row to be returned to the client which initiated the saving of the form, so that it may save it in the corresponding cell in table A.
Is this possible with (mostly) the dataprocessor?
(Otherwise I can think of doing this “manually” through various ajax calls…)
About form
You can insert new row through dhtmlxForm
form.save will add new row to the related table, when you are using dataprocessor with form
It will work only if you are saving an empty form. If you have something like
form.load(“some.php?id=123”);
where 123 - not existing id, attempt to save the form will result in UPDATE operation, not insert.
About form and grid usage
In your case it can be a more direct approach to add row to the grid, and select it after that. So grid will create a new record in the table and the form will work always in UPDATE mode.
And just to be clear, it is not possible to have new row added to the table after saving the empty form. ( it looks as a place for improvement in the next update )
Okay, thanks for advise, well appreciated.