Answers.Body: <p>This should be it:</p>
  
  <pre><code>    $mode = $form-&gt;getVar('_mode');
      // civicrm mumbo jumbo below targets EDIT form mode
      if (in_array($mode, array(CRM_Profile_Form::MODE_EDIT))) 
      {}
  </code></pre>
  
  <p>But it doesn't work for all forms, so, for example, for Relationship add/edit form, we should check if <strong>$form->getVar('_relationshipId')</strong>  isset/empty :
  thus no Relationship has been created  yet: we are in Relationship ADD "mode". </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-09T22:57:34.003Z
Answers.LastActivityDate: 2016-02-11T11:40:39.333Z
Answers.LastEditDate: 2016-02-11T11:40:39.333Z
Answers.UserDisplayName: yurg
Body: <p>Is it possible in hook_buildForm to define which "$action" link (view/add/update/delete/etc) opens the form? We need to set different $defaults depending on "context". There is such kind of detection/check in TPL files, but what about hook_buildForm?  </p>
  
Tags: <hooks>
Title: Add/Update form actions(context?) detection from hook_buildForm
ThreadText: # Add/Update form actions(context?) detection from hook_buildForm
  
  (Asked by: username_0 on 2016-01-28)
  
  Is it possible in hook\_buildForm to define which "$action" link (view/add/update/delete/etc) opens the form? We need to set different $defaults depending on "context". There is such kind of detection/check in TPL files, but what about hook\_buildForm?
  
  **Tags:** hooks
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2016-02-09. Score: 1 | Accepted answer
  
  This should be it:
      $mode = $form->getVar('_mode');
      // civicrm mumbo jumbo below targets EDIT form mode
      if (in_array($mode, array(CRM_Profile_Form::MODE_EDIT))) 
      {}
  
  But it doesn't work for all forms, so, for example, for Relationship add/edit form, we should check if $form->getVar('_relationshipId')  isset/empty :
  thus no Relationship has been created  yet: we are in Relationship ADD "mode".
  
  
  ---
  
  