Weird Question - Tracking Changes...

Parisi

Member
I have a weird question - I have a simple table

ID, Date, Data, Parent
1, 1/1/2015, Red, 0
2, 1/1/2015, Blue, 0

If a user edits row 2 I want to create a new row, not edit row 2, so create row 3 as a copy of row 2, and the user edits it and saves the record. The parent would point back to the original record.

3, 2/1/2015, Orange, 2

How would I go about doing this in Fabrik?

Thanks in advance for your help!
Paul.
 
You might be able to do that with a PHP submission plugin, running onBeforeProcess:

Code:
if ((int)$formModel->rowId !== 0) {
   $formModel->formData['yourtable___parent_id'] = $formModel->rowId;
   $formModel->formData['yourtable___parent_id_raw'] = $formModel->rowId;
   $formModel->formData['rowid'] = '';
   $formModel->formData['__pk_val'] = '';
   $formModel->formData['yourtable___id'] = '';
   $formModel->formData['yourtable___id_raw'] = '';
   $formModel->rowId = '';
}

This code unsets the references to the rowid being edited/saved, and sets your parent_id to that rowid. So a new row should get created. I did a quick test on a very simple table, it works.

Obviously substitute your full elements names as appropriate.

NOTE that this won't handle list joins - the original joined row(s) won't get copied, and would remain related to the original row. It may also not work right for some elements, like (say) uploads, which would then have two rows referencing the same file, or for any elements that use implicit joins (like multi-select joins, etc).

But your your simple example it should work.

-- hugh
 
What about using the "Save as copy" button and e.g. removing the "Save" button in a custom template (if record <> new)?
 
Yeah, that would work, apart from not setting the parent_id. Although that could probably be done by just cutting that plugin code I gave back to just setting parent_id from $formModel->rowId.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Staff online

Members online

Back
Top