Answers.Body: <p>The best approach is probably to use the <a href="https://craftcms.com/classreference/fieldtypes/BaseElementFieldType#onAfterElementSave-detail" rel="nofollow"><code>onAfterElementSave</code></a> hook available to custom fieldtypes. Here's what that could look like (the following method should go into your custom fieldtype class, e.g. <code>myawesomeplugin/fieldtypes/MyAwesomePluginFieldType.php</code>):</p>
  
  <pre><code>public function onAfterElementSave()
  {
      $field = $this;
      $fieldId = $this-&gt;model-&gt;id;
      $fieldHandle = $this-&gt;model-&gt;handle;
      $element = $this-&gt;element; // This is the UserModel, in your case
      $fieldContent = $element-&gt;getContent()-&gt;getAttribute($fieldHandle); // This is the content for the field
  
      // Do something awesome with the data above
      ...
  
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-28T11:28:55.530Z
Answers.Text: Thanks for the reply, and i love the onAfterElementSave().
  But i need to use the business field from my CustomField Type to be saved after the user is saved in a address model.
  
  I am only getting the UserModel and not the AddressModel to populate it.
Answers.UserDisplayName: Bram B
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-28T09:36:05.863Z
Answers.LastActivityDate: 2016-10-28T09:54:24.270Z
Answers.LastEditDate: 2016-10-28T09:54:24.270Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Body: <p>I have made a custom fieldtype.</p>
  
  <pre><code>{% import "_includes/forms" as forms %}
  
  {{ forms.textField({
      label: "business"|t,
      required: true,
  }) }}
  </code></pre>
  
  <p>And added it to the user fields.
  Where do I need to save data entered in at a user profile.</p>
  
  <p>I would like to hook into the <code>onSaveUser</code> event with my plugin to save my values into the address model of Craft Commerce, but how would I do that?</p>
  
  <p>An example would be appreciated.</p>
  
Tags: <plugin-development><plugin-craftcommerce>
Title: Custom Fieldtype in a plugin at user profile save
ThreadText: # Custom Fieldtype in a plugin at user profile save
  
  (Asked by: username_0 on 2016-10-28)
  
  I have made a custom fieldtype.
  
  ```
  {% import "_includes/forms" as forms %}
  
  {{ forms.textField({
      label: "business"|t,
      required: true,
  }) }}
  
  ```
  
  And added it to the user fields.
  Where do I need to save data entered in at a user profile.
  
  I would like to hook into the `onSaveUser` event with my plugin to save my values into the address model of Craft Commerce, but how would I do that?
  
  An example would be appreciated.
  
  **Tags:** plugin-development, plugin-craftcommerce
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-10-28. Score: 3
  
  The best approach is probably to use the [`onAfterElementSave`](https://craftcms.com/classreference/fieldtypes/BaseElementFieldType#onAfterElementSave-detail) hook available to custom fieldtypes. Here's what that could look like (the following method should go into your custom fieldtype class, e.g. `myawesomeplugin/fieldtypes/MyAwesomePluginFieldType.php`):
  
  ```
  public function onAfterElementSave()
  {
      $field = $this;
      $fieldId = $this->model->id;
      $fieldHandle = $this->model->handle;
      $element = $this->element; // This is the UserModel, in your case
      $fieldContent = $element->getContent()->getAttribute($fieldHandle); // This is the content for the field
  
      // Do something awesome with the data above
      ...
  
  }
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks for the reply, and i love the onAfterElementSave(). But i need to use the business field from my CustomField Type to be saved after the user is saved in a address model.  I am only getting the UserModel and not the AddressModel to populate it.  
  
  ---
  
  