Answers.Body: <p>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.</p>
  
  <p>HTH</p>
  
  <p>Pradeep</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-27T20:17:13.333Z
Answers.Text: Pradeep, thanks, but where in validateForm does it say which action is being taken and which element is being deleted?  Also, https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_pre/ says that pre will not abort an operation?
Answers.UserDisplayName: Paul B
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-27T20:20:36.007Z
Answers.Text: 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.
Answers.UserDisplayName: Pradeep Nayak
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-28T00:50:11.437Z
Answers.Text: 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?
Answers.UserDisplayName: Paul B
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-27T20:14:01.260Z
Answers.LastActivityDate: 2018-04-27T20:14:01.260Z
Answers.UserDisplayName: Pradeep Nayak
Body: <p>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?</p>
  
  <p>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).</p>
  
  <p>Is there another hook I should be using for this?</p>
  
  <p>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.</p>
  
  <p>Would love some pointers on either method.  Thanks!</p>
  
Tags: <email><hooks>
Title: Hook to stop a contact's email from being deleted
ThreadText: # Hook to stop a contact's email from being deleted
  
  (Asked by: username_0 on 2018-04-27)
  
  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!
  
  **Tags:** email, hooks
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-04-27. Score: 0
  
  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
  
  username_1
  
  > **Comments:**
  > **username_0**: username_1, thanks, but where in validateForm does it say which action is being taken and which element is being deleted?  Also, https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_pre/ says that pre will not abort an operation?  
  > **username_1**: 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.  
  > **username_0**: 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?  
  
  ---
  
  