Intercept error message when delete fails

Hello All,

I am trying to intercept a technical error message for a foreign key violation that is happening when a user tries to delete a parent record that still has child records associated with it.
Of course, this is the correct behavior.
My issue is that I want to intercept this message and change it from technical gibberish (from the end user’s perspective) to some more user friendly.
I thought I was being clever when I found the “Message_Showing” event on the Delete Page and put my more friendly end user message under the elseif branch for ‘failure’.
However, when the Delete confirmation page loaded it displayed the message. To me the message should not display until the user actually clicks on the “Delete” button.

Any idea where I am going awry?

Thanks!

craigbert

You should check the original message in Message_Showing event and change it to your user-friendly message only if the specific message is present (not always set the failure message).

Thanks for the response.
In the Delete Page, Message_Showing event I see the following code:

// Message Showing event
// $type = ‘’|‘success’|‘failure’|‘warning’
function Message_Showing(&$msg, $type) {
if ($type == ‘success’) {
//$msg = “your success message”;
} elseif ($type == ‘failure’) {
//$msg = “your failure message”;
} elseif ($type == ‘warning’) {
//$msg = “your warning message”;
} else {
//$msg = “your message”;
}
}

If I uncomment the failure message, save the project, go to the list page, click on Delete it takes me to the delete page and displays “your failure message”. At this point I have not attempted to actually delete the record.

So if I understand you correctly I should add another “if” statement w/n this structure and check for the failure message that talks about the FK violation and if that one gets a hit then populate the $msg variable otherwise do nothing. Is that correct?

I can certainly do that, but it seems…clumsy to me.

Thanks,

craigbert

craigbert wrote:

So if I understand you correctly I should add another “if”
statement w/n this structure and check for the failure message that talks
about the FK violation and if that one gets a hit then populate the $msg
variable otherwise do nothing. Is that correct?

Yes, because it can be other failure message.

That worked, thanks!

I do have a follow up question though: how can we tell when this method/function is being called?
When I uncommented all of them they all fired.

Thanks,

craigbert

The event is always called on page load so that the messages (if set in previous page) will be shown.