Forums

handle database error

ilmagowalter 19 Feb, 2016
Hi,
i would like know if there is a way to handle db error after a db operation

Example:
1) when i try to delete a record that have reference to other table ( foreign key )
2) when i try to insert a record ( through ChronoForm ) that violated a unique constraint

i mean send a message to user
GreyHead 19 Feb, 2016
Hi ilmagowalter,

There's nothing built-in to do this - but you can do it using custom code
<?php
$jdoc = \JFactory:;getDocument();
$jdoc->enqueueMessage('Some message');
// possibly also 
// $jdoc->redirect('Some_url');
?>

You could also use the Event Switcher if you prefer.

Bob
ilmagowalter 19 Feb, 2016
do you have some examples ?
and where i have to put custom code ? in which event of setup for chronoform ?
and for chrono connectivity ?
GreyHead 19 Feb, 2016
Hi ilmagowalter,

Examples of what exactly?

Bob
ilmagowalter 20 Feb, 2016
ok, there are 2 scenary
1) CCv5
i have a list of records ( img1.png )
i try to delete one record ( ID 4 )
this id is used in referenced table, so i cannot delete
now the system give error like in img2.png
i would like that the system give the message ( in the same place of we can see the "saved" message )
"the device with ID 4 cannot delete because used in table xxx"

2) CFv5
from CCv5 i have a list of records ( img1.png )
i click on NEW ( img3.png )
i fill the form but i put a "SIM number" existing
now the system give the errore like in img4.png
i would like that the system give the message ( like CCv5 message )
"the SIM NUMBER +393471111111 is already used"
GreyHead 20 Feb, 2016
Hi ilmagowalter,

Case 2 you can do with an Event Switcher in the form. The code in the Event Switcher needs to query the table to see if there is an 'error' or not.

Case1 is a bit more complicated. I don't think that the standard CC Delete link so you'd need a custom link to a form event and then use the Event Switcher to do the check.

Bob
This topic is locked and no more replies can be posted.