0

We have a new requirement to stop an admin from deleting a contact's email if that email is found in one of our other systems. I am trying to do this through a validateForm hook. I can figure out the logic of finding the email in another system. But how can I check: 1. That the form is trying to delete or update an email (vs adding an email)? 2. Identify which email is being deleted?

I can't tell where to find the action being taken, nor which email is being deleted. Also, if I set an error (as a test), the error shows correctly, but the deleted email is gone from the view of the form (I would like for it to stay there).

Is there another hook I should be using for this?

My other option would be to use the buildForm or similar hook to make that field readonly prior to the form showing up. But I feel it's safer to block a delete.

Would love some pointers on either method. Thanks!

1

You can use ValidateForm to check all form level action. Also you can use pre hook to check if email is being deleted or updated and then throw fatal error or exception.

HTH

Pradeep

  • Pradeep, thanks, but where in validateForm does it say which action is being taken and which element is being deleted? Also, docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_pre says that pre will not abort an operation? – Paul B Apr 27 '18 at 20:17
  • Use form action i.e $form->_action to check if its a delete or update action. You can throw exception or fatal error in pre hook. I believe if its a fatal error then all the db transaction will rollback, however it won't be an user friendly error. – Pradeep Nayak Apr 27 '18 at 20:20
  • thanks, but the $form->_action in validateForm for CRM_Contact_Form_Inline_Email always seems to be equal to 2 no matter if I'm deleting or updating, and that doesn't seem to match CRM_Core_ACTION::DELETE (which is 8, I think). What am I missing? – Paul B Apr 28 '18 at 0:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.