Answers.Body: <p>I'd suggest you create 2 custom fields for this in the activity (pickup location &amp; contact phone number). You can then use a bit of javascript to insert the contact's email &amp; phone into those fields and it will come through in the activity email. As an added bonus, this approach gives the flexibility of allowing the user to override those defaults if the person needs to be picked up elsewhere.</p>
  
  <p>To do this, your buildform hook needs to do 2 things:</p>
  
  <ol>
  <li><p>Request the extra address/phone info from the target_contact_id field. You can do:</p>
  
  <pre><code>$form-&gt;_fields['target_contact_id']['attributes']['api']['extra'] = array(
    'street_address',
    'city',
    'state_province',
    'postal_code',
    'phone',
  );
  </code></pre></li>
  <li><p>Add your javascript to the form using <a href="http://wiki.civicrm.org/confluence/display/CRMDOC/Resource+Reference" rel="nofollow">CRM_Core_Resources</a> (hint: create a js file in your extension, and use <code>CRM_Core_Resources::singleton()-&gt;addScriptFile('myExtension', 'js/myScript.js')</code>)</p></li>
  </ol>
  
  <p>Your javascript can then use some basic jQuery like:</p>
  
  <pre><code>CRM.$(function($) {
    $('#target_contact_id').change(function() {
      if ($(this).val()) {
        // This contains the extra fields you requested
        var data = $(this).select2('data')[0].extra;
        // For example, populate a custom field with the phone
        $('#custom_42').val(data.phone);
      }
    });
  });
  </code></pre>
  
  <p>You can <a href="http://wiki.civicrm.org/confluence/display/CRMDOC/Javascript+Reference" rel="nofollow">read more about javascript in CiviCRM here</a>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-01T01:55:15.260Z
Answers.Text: Awesome! Worked like a charm. You're crushing it on this StackExchange. Thanks again for all your hard work on here.
Answers.UserDisplayName: Sean
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-01T02:01:45.620Z
Answers.Text: Glad to help. Good luck with your project :)
Answers.UserDisplayName: Coleman
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-02T00:20:15.690Z
Answers.Text: @Sean - curious to see how your code turned out - want to paste a link to it (on github, gist, etc.)
Answers.UserDisplayName: Coleman
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-04T15:46:40.963Z
Answers.Text: Absolutely, I'm vacationing in the mountains and have limited access to the internet. I will send it over to you as soon as I get back.
Answers.UserDisplayName: Sean
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-01T01:29:10.143Z
Answers.LastActivityDate: 2015-07-01T01:50:48.283Z
Answers.LastEditDate: 2015-07-01T01:50:48.283Z
Answers.UserDisplayName: Coleman
Body: <p>I'm writing an extension to customize the create new activity page. I need to add the 'With Contact' address and phone number to the page. When editing the /civicrm/CRM/Activity/Form/Activity.php how do you get the address to propagate when the contact is selected? Here is what I'm trying to edit:</p>
  
  <pre><code>    ),
     'target_contact_id' =&gt; array(
     'type' =&gt; 'entityRef',
     'label' =&gt; ts('With Contact'),
     'attributes' =&gt; array('multiple' =&gt; TRUE, 'create' =&gt; TRUE),
      ),
     'target_contact_adress' =&gt; array(
     'type' =&gt; 'entityRef', //I'm guessing I need to change this line to call the address?
     'label' =&gt; ts('With Contact Address'),
     'attributes' =&gt; array('multiple' =&gt; TRUE, 'create' =&gt; TRUE),
      ),
  </code></pre>
  
  <p>Edit: To better explain what I'm trying to do. I'm creating a custom extension for an organization that uses the Activity assignment notification to email their volunteers that don't have access to the CiviCRM database contact information (Phone Numbers and Addresses) about their members. In order to do this I need to add two fields that pull this information when a contact is selected.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-06-30T20:10:24.607Z
Comments.Text: I assume your code is part of a buildForm hook?
Comments.UserDisplayName: Coleman
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-06-30T20:11:43.157Z
Comments.Text: I think I could answer your question if I knew exactly what you were asking. You want to create a new form field to select... what exactly? And why?
Comments.UserDisplayName: Coleman
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-06-30T20:47:43.810Z
Comments.Text: Correct, It's part of a buildFrom hook. The form field should select the address/phone number of the selected entity (Individual). Why, because this organization is using the Activity email notification to let their volunteers know the number and address of their "members". Thank you for any help.
Comments.UserDisplayName: Sean
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-06-30T21:09:56.113Z
Comments.Text: Still trying to understand... so once they've selcted the "With Contact" (note this can be multivalued!) you want them to be able to select one of potentially multiple addresses/phones for that contact? And why? What will the form submission do with that information?
Comments.UserDisplayName: Coleman
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-06-30T21:32:05.330Z
Comments.Text: Sorry for not being clear. This is my first extension for CiviCRM. I'm using this project to learn. Let me give an example scenario. This organization assists elders in the community by providing services, one of these services is to give rides to various places (let's say a pharmacy). So, they need a volunteer (the assigned to contact) to give a ride to the elder (the with contact). When an activity is assigned the volunteer gets a notification by email (Volunteers do not have access to CiviCRM). Now, there is already a location field (the pharmacy). Countinued...
Comments.UserDisplayName: Sean
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-06-30T21:36:49.773Z
Comments.Text: but they still need to know where to pick the elder up at (the "with contacts" home address). So, I need a field that pulls this information. It would also be nice to add the "With Contact" home phone as well.
Comments.UserDisplayName: Sean
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-06-30T21:51:37.620Z
Comments.Text: Thanks, I think I understand what you need to do. While I'm working on an answer, could you please edit your question to incorporate your comments to better describe the scenario? (for the sake of the next person trying to do something similar)
Comments.UserDisplayName: Coleman
Tags: <extension><php>
Title: Fill Address/Phone enityRef
ThreadText: # Fill Address/Phone enityRef
  
  (Asked by: username_0 on 2015-06-30)
  
  I'm writing an extension to customize the create new activity page. I need to add the 'With Contact' address and phone number to the page. When editing the /civicrm/CRM/Activity/Form/Activity.php how do you get the address to propagate when the contact is selected? Here is what I'm trying to edit:
  
  ```
      ),
     'target_contact_id' => array(
     'type' => 'entityRef',
     'label' => ts('With Contact'),
     'attributes' => array('multiple' => TRUE, 'create' => TRUE),
      ),
     'target_contact_adress' => array(
     'type' => 'entityRef', //I'm guessing I need to change this line to call the address?
     'label' => ts('With Contact Address'),
     'attributes' => array('multiple' => TRUE, 'create' => TRUE),
      ),
  
  ```
  
  Edit: To better explain what I'm trying to do. I'm creating a custom extension for an organization that uses the Activity assignment notification to email their volunteers that don't have access to the CiviCRM database contact information (Phone Numbers and Addresses) about their members. In order to do this I need to add two fields that pull this information when a contact is selected.
  
  **Tags:** extension, php
  
  > **Comments:**
  > **username_1**: I assume your code is part of a buildForm hook?  
  > **username_1**: I think I could answer your question if I knew exactly what you were asking. You want to create a new form field to select... what exactly? And why?  
  > **username_0**: Correct, It's part of a buildFrom hook. The form field should select the address/phone number of the selected entity (Individual). Why, because this organization is using the Activity email notification to let their volunteers know the number and address of their "members". Thank you for any help.  
  > **username_1**: Still trying to understand... so once they've selcted the "With Contact" (note this can be multivalued!) you want them to be able to select one of potentially multiple addresses/phones for that contact? And why? What will the form submission do with that information?  
  > **username_0**: Sorry for not being clear. This is my first extension for CiviCRM. I'm using this project to learn. Let me give an example scenario. This organization assists elders in the community by providing services, one of these services is to give rides to various places (let's say a pharmacy). So, they need a volunteer (the assigned to contact) to give a ride to the elder (the with contact). When an activity is assigned the volunteer gets a notification by email (Volunteers do not have access to CiviCRM). Now, there is already a location field (the pharmacy). Countinued...  
  > **username_0**: but they still need to know where to pick the elder up at (the "with contacts" home address). So, I need a field that pulls this information. It would also be nice to add the "With Contact" home phone as well.  
  > **username_1**: Thanks, I think I understand what you need to do. While I'm working on an answer, could you please edit your question to incorporate your comments to better describe the scenario? (for the sake of the next person trying to do something similar)  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-07-01. Score: 2 | Accepted answer
  
  I'd suggest you create 2 custom fields for this in the activity (pickup location & contact phone number). You can then use a bit of javascript to insert the contact's email & phone into those fields and it will come through in the activity email. As an added bonus, this approach gives the flexibility of allowing the user to override those defaults if the person needs to be picked up elsewhere.
  
  To do this, your buildform hook needs to do 2 things:
  
  1. Request the extra address/phone info from the target\_contact\_id field. You can do:
  
     ```
     $form->_fields['target_contact_id']['attributes']['api']['extra'] = array(
       'street_address',
       'city',
       'state_province',
       'postal_code',
       'phone',
     );
  
     ```
  2. Add your javascript to the form using [CRM\_Core\_Resources](http://wiki.civicrm.org/confluence/display/CRMDOC/Resource+Reference) (hint: create a js file in your extension, and use `CRM_Core_Resources::singleton()->addScriptFile('myExtension', 'js/myScript.js')`)
  
  Your javascript can then use some basic jQuery like:
  
  ```
  CRM.$(function($) {
    $('#target_contact_id').change(function() {
      if ($(this).val()) {
        // This contains the extra fields you requested
        var data = $(this).select2('data')[0].extra;
        // For example, populate a custom field with the phone
        $('#custom_42').val(data.phone);
      }
    });
  });
  
  ```
  
  You can [read more about javascript in CiviCRM here](http://wiki.civicrm.org/confluence/display/CRMDOC/Javascript+Reference).
  
  > **Comments:**
  > **username_0**: Awesome! Worked like a charm. You're crushing it on this StackExchange. Thanks again for all your hard work on here.  
  > **username_1**: Glad to help. Good luck with your project :)  
  > **username_1**: @username_0 - curious to see how your code turned out - want to paste a link to it (on github, gist, etc.)  
  > **username_0**: Absolutely, I'm vacationing in the mountains and have limited access to the internet. I will send it over to you as soon as I get back.  
  
  ---
  
  