Answers.Body: <p>you need to create an extension and use the buildForm hook.</p>
  <p>More information on creating an extension can be found here: <a href="https://docs.civicrm.org/dev/en/latest/extensions/" rel="nofollow noreferrer">https://docs.civicrm.org/dev/en/latest/extensions/</a></p>
  <p>More information on the buildForm hook: <a href="https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_buildForm/" rel="nofollow noreferrer">https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_buildForm/</a>
  This contains an example of adding a field.</p>
  <p>Another example of adding a field with the buildForm hook:</p>
  <pre><code>if ($studyNumber) {
    $form-&gt;addElement('text', 'study_number', &quot;Study Number&quot;, ['readonly' =&gt; 'readonly']);
    $form-&gt;setDefaults(['study_number' =&gt; $studyNumber]);
    CRM_Core_Region::instance('page-body')-&gt;add(['template' =&gt; 'CRM/Nihrbackbone/nbr_study_number.tpl',]);
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-20T09:43:14.260Z
Answers.LastActivityDate: 2020-10-20T09:43:14.260Z
Answers.UserDisplayName: ErikH - CiviCooP
Body: <p>I'd like to change the form that opens when adding an Activity to a Case (depending on activity type). Specifically, I'd like to add a field.
  I tried finding the fields I want to change in sites/all/modules/civicrm/CRM/Case/Form/Activity.php but couldn't find them. It seems like the buildQuickForm() function is only creating some of the visible fields but not all.
  I also thought about writing an extension based on the hook_civicrm_buildForm function. I want to start checking if <code>$formName == 'CRM_Case_Form_Activity'</code> but after that I don't really know where to start. Can anyone give me a hint?</p>
  <p>Edit: I found an extension changing the same location looking like this (<a href="https://civicrm.stackexchange.com/questions/4399/how-can-i-set-assigned-to-for-an-activity-to-default-to-the-logged-in-user-nam">How can I set &quot;Assigned To&quot; for an Activity to default to the logged-in user name?</a>):</p>
  <pre><code>function myextension_civicrm_buildForm($formName, &amp;$form) {
    if ($formName == 'CRM_Activity_Form_Activity' &amp;&amp; $form-&gt;getAction() == CRM_Core_Action::ADD) {
      $form-&gt;setDefaults(array('assignee_contact_id' =&gt; $form-&gt;_currentUserId));
    }
  }
  </code></pre>
  <p>Is there anything like <code>$form-&gt;addField</code> or something?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-10-20T11:22:46.993Z
Comments.Text: Did you look at custom fields? (Admin - Customize - Custom Fields) You can create them for activities for either all types or just some types.
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-10-20T11:46:19.900Z
Comments.Text: I tried that now, but the field doesn't appear. I think this is because the activity where I want to add a field is not a normal activity but a "create email" activity
Comments.UserDisplayName: emma
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-10-20T11:48:12.817Z
Comments.Text: Ok yes emails are a bit different.
Comments.UserDisplayName: Demerit
Tags: <civicase><hooks>
Title: Adding a field to the Create Activity Form
ThreadText: # Adding a field to the Create Activity Form
  
  (Asked by: username_0 on 2020-10-20)
  
  I'd like to change the form that opens when adding an Activity to a Case (depending on activity type). Specifically, I'd like to add a field.
  I tried finding the fields I want to change in sites/all/modules/civicrm/CRM/Case/Form/Activity.php but couldn't find them. It seems like the buildQuickForm() function is only creating some of the visible fields but not all.
  I also thought about writing an extension based on the hook\_civicrm\_buildForm function. I want to start checking if `$formName == 'CRM_Case_Form_Activity'` but after that I don't really know where to start. Can anyone give me a hint?
  
  Edit: I found an extension changing the same location looking like this ([How can I set "Assigned To" for an Activity to default to the logged-in user name?](https://civicrm.stackexchange.com/questions/4399/how-can-i-set-assigned-to-for-an-activity-to-default-to-the-logged-in-user-nam)):
  
  ```
  function myextension_civicrm_buildForm($formName, &$form) {
    if ($formName == 'CRM_Activity_Form_Activity' && $form->getAction() == CRM_Core_Action::ADD) {
      $form->setDefaults(array('assignee_contact_id' => $form->_currentUserId));
    }
  }
  
  ```
  
  Is there anything like `$form->addField` or something?
  
  **Tags:** civicase, hooks
  
  > **Comments:**
  > **username_1**: Did you look at custom fields? (Admin - Customize - Custom Fields) You can create them for activities for either all types or just some types.  
  > **username_0**: I tried that now, but the field doesn't appear. I think this is because the activity where I want to add a field is not a normal activity but a "create email" activity  
  > **username_1**: Ok yes emails are a bit different.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2020-10-20. Score: 1 | Accepted answer
  
  you need to create an extension and use the buildForm hook.
  
  More information on creating an extension can be found here: <https://docs.civicrm.org/dev/en/latest/extensions/>
  
  More information on the buildForm hook: <https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_buildForm/>
  This contains an example of adding a field.
  
  Another example of adding a field with the buildForm hook:
  
  ```
  if ($studyNumber) {
    $form->addElement('text', 'study_number', "Study Number", ['readonly' => 'readonly']);
    $form->setDefaults(['study_number' => $studyNumber]);
    CRM_Core_Region::instance('page-body')->add(['template' => 'CRM/Nihrbackbone/nbr_study_number.tpl',]);
  }
  
  ```
  
  
  ---
  
  