On record deletion (onDeleteRowsForm) question

Hi,

We create company;s with employees and customers on our website. We connect the data via a bedrijf_id (company_id)

The data is stored in different tables.

Now, when we want to delete a company from the website (if they cancel subscription) we want also the connected data dissapear from the other tables.

I tried to achieve this with a php plugin (in the form).

In the plugin we set: On record deletion (onDeleteRowsForm)

Then as code we set:


Code:
$bedrijfid = '{egocentralis_bedrijven___bedrijf_id}';

  $db_deletef = FabrikWorker::getDbo();

$query_deletef = $db_deletef->getQuery(true);
$query_deletef
  ->delete('g4e_orakel_functies')
  ->where('bedrijf_id = ' $mydb->quote($bedrijfid));
 
$db_deletef->setQuery($query_deletef);

$query_deleteu = $db_deletef->getQuery(true);
$query_deleteu
  ->delete('g4e_orakel_urencode')
  ->where('bedrijf_id = ' $mydb->quote($bedrijfid));
 
$db_deletef->setQuery($query_deleteu);
$db_deletef->execute();

But when clicking delete, and confirm the deletion we get a spinning wheel and nothing happens.

We tried to adjust the query a bit but that did not help.

How can we get it like when pressing delete, all data from the other tables will be deleted also??
 
You have syntax error in your code.
Try with tihs:
PHP:
$bedrijfid = '{egocentralis_bedrijven___bedrijf_id}';

$db_deletef = FabrikWorker::getDbo();

$query_deletef = $db_deletef->getQuery(true);
$query_deletef
  ->delete('g4e_orakel_functies')
  ->where('bedrijf_id = ' . $mydb->quote($bedrijfid));
$db_deletef->setQuery($query_deletef);

$query_deleteu = $db_deletef->getQuery(true);
$query_deleteu
  ->delete('g4e_orakel_urencode')
  ->where('bedrijf_id = ' . $mydb->quote($bedrijfid));
$db_deletef->setQuery($query_deleteu);
$db_deletef->execute();
 
Attention with onDeleteRecord, the code is run with the Delete button in the form but also with Delete in the list.

https://fabrikar.com/forums/index.p...leterowsform-trigger-works.48475/#post-252810

So you should wrap your code in a loop
foreach ($data as $group) {
foreach ($group as $row) {
// your rowid will be in $row->__pk_val
// elements will be in $row->tablename___fieldname
}
}
and use $row->tablename___fieldname instead of {tablename___fieldname}.
Otherwise Delete in list will break.
 
Last edited:
Attention with onDeleteRecord, the code is run with the Delete button in the form but also with Delete in the list.

https://fabrikar.com/forums/index.p...leterowsform-trigger-works.48475/#post-252810

So you should wrap your code in a loopotherwise Delete in list will break.


Oh wow Troester, this is the first time that what you wrote is abracadabra for me.

By removing from the list you mean:

Screenshot_110.png

What is __pk_val?

and then, in place of $db_deletef->execute(); I need to write something like $data->loadObjectlist();

I did read the info on the link you sended to me, but that is too high level with too less information for me.

I hope you can clarify this a bit more for a dummie.. :)
 
I struggled with this onDeleteRecord long time ago and got it working with the help of Rob and Hugh.

The abracadabra is from Hugh's post;)

Because the code in the php form plugin is also trigged if you delete records in your list view it needs this loop.
In the form this is not really relevant (the "loop" is exactly run once) but the deletion in the list needs this (you can delete multiple records and in the list you can't use element placeholders).

__pk_val is the primary key value, you can also use your internalid element.
in place of $db_deletef->execute(); I need to write something like $data->loadObjectlist();
No, $data is set by Fabrik, don't touch it.

BTW:
If g4e_orakel_functies and g4e_orakel_urencode are joined in the egocentralis list you can enable "Delete joined data" in the list's "Joins" settings. I think this will also do if deleting from form view. But test carefully.
 
Last edited:
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top