Answers.Body: <p>Here's the issue:</p>
  
  <pre><code>// Add dynamic fields
  $entry-&gt;setContentFromPost(craft()-&gt;request-&gt;getParam('fields'));
  </code></pre>
  
  <p><a href="https://craftcms.com/classreference/models/BaseElementModel" rel="nofollow">setContentFromPost</a> requires that if you pass any uploaded files in, you need to pass the field name as a string, instead of the actual posted values.</p>
  
  <p>Changing it to this and it should work:</p>
  
  <pre><code>$entry-&gt;setContentFromPost('fields');
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-18T22:16:54.180Z
Answers.LastActivityDate: 2016-01-18T22:16:54.180Z
Answers.UserDisplayName: Brad Bell
Body: <p>I'm having issues saving an Asset field in my <em>FEEF</em> using a Plugin. I have a channel with some fields added to it, one of these fields being an Asset field. When using the standard <strong>entries/saveEntry</strong> build in function in Craft the Asset gets saved.</p>
  
  <p>When I try to run the same form (same channel, same field) through my Plugin everything saves except the Asset field asset. The code I'm using (below) is a slightly changed version of Pixel&amp;Tonics own "<em>Guest Entries</em>" Plugin.</p>
  
  <p>Can anyone help me to figure out whats going on?</p>
  
  <pre><code>/**
   * Populates an EntryModel with post data.
   *
   * @access private
   * @throws HttpException
   * @return EntryModel
   */
  private function _populateEntryModel()
  {
      $entry = new EntryModel();
  
      // Set section
      $entry-&gt;sectionId   = craft()-&gt;request-&gt;getRequiredPost('sectionId');
      $this-&gt;_section     = craft()-&gt;sections-&gt;getSectionById($entry-&gt;sectionId);
      $this-&gt;_entryTypeId = craft()-&gt;request-&gt;getPost('entryTypeId');
  
      // Default
      $entry-&gt;authorId    = 1;
      $entry-&gt;enabled     = true;
  
      // Set title
      $entry-&gt;getContent()-&gt;title = craft()-&gt;request-&gt;getPost('title');
  
      // Set Entry type
      if($this-&gt;_entryTypeId)
      {
          $entry-&gt;typeId = $this-&gt;_entryTypeId;
      }
  
      // Add dynamic fields
      $entry-&gt;setContentFromPost(craft()-&gt;request-&gt;getParam('fields'));
  
      // Return model
      return $entry;
  }
  </code></pre>
  
  <p>This is how my form looks (I've removed some styling and keept the essentials)</p>
  
  <pre><code>&lt;form method="post" action="" accept-charset="UTF-8" enctype="multipart/form-data"&gt;
  
  &lt;!-- Hidden --&gt;
  {{ getCsrfInput() }}
  &lt;input type="hidden" name="action" value="forms/saveEntry"&gt;
  &lt;input type="hidden" name="redirect" value="{{ craft.request.url }}?sent=1"&gt;
  &lt;input type="hidden" name="sectionId" value="13"&gt;
  &lt;input type="hidden" name="entryTypeId" value="18"&gt;
  &lt;input type="hidden" name="title" class="title" value=""/&gt;
  
  &lt;input type="text" name="fields[formName]" value="{% if formEntry.formName is defined %}{{ formEntry.formName }}{% endif %}" class="default-field name" /&gt;
  &lt;input type="text" name="fields[formConfirmationNumber]" value="{% if formEntry.formConfirmationNumber is defined %}{{ formEntry.formConfirmationNumber }}{% endif %}" class="default-field" /&gt;
  &lt;input type="text" name="fields[formRoom]" value="{% if formEntry.formRoom is defined %}{{ formEntry.formRoom }}{% endif %}" class="default-field" /&gt;
  &lt;input type="file" name="fields[formFile]"&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>The name="title" field gets set dynamic...</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-01-14T20:00:22.543Z
Comments.Text: What does your front-end form look like?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-01-16T06:59:22.643Z
Comments.Text: Added it to the original post @BradBell.
Comments.UserDisplayName: naboovalley
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-01-16T07:00:10.753Z
Comments.Text: Also the site uses Craft Pro 2.4.2702. Don't know if that makes a difference.
Comments.UserDisplayName: naboovalley
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-01-17T00:20:08.943Z
Comments.Text: Hrm... before I setup a test case, any chance you can update to the latest 2.5 to see if it helps?  Lots of enhancement and bug fixes in it.
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-01-17T09:32:24.363Z
Comments.Text: Since its a quite large site I would like to troubleshoot it as is before running an update. I'm wondering if it has anything to do with me setting the "Entry Type" ID? Because when running it through entries/saveEntry I need to have the targeted "Entry Type" as the root one in the list (it needs to be sorted as default/top entry type in list) since entries/saveEntry doesn't support multiple entry types (I think?). Anything around this we can dig around in @BradBell?
Comments.UserDisplayName: naboovalley
Tags: <plugin-development><assets>
Title: Saving Asset field in FEEF ("Front-end entry form") using Plugin
ThreadText: # Saving Asset field in FEEF ("Front-end entry form") using Plugin
  
  (Asked by: username_0 on 2016-01-14)
  
  I'm having issues saving an Asset field in my *FEEF* using a Plugin. I have a channel with some fields added to it, one of these fields being an Asset field. When using the standard **entries/saveEntry** build in function in Craft the Asset gets saved.
  
  When I try to run the same form (same channel, same field) through my Plugin everything saves except the Asset field asset. The code I'm using (below) is a slightly changed version of Pixel&Tonics own "*Guest Entries*" Plugin.
  
  Can anyone help me to figure out whats going on?
  
  ```
  /**
   * Populates an EntryModel with post data.
   *
   * @access private
   * @throws HttpException
   * @return EntryModel
   */
  private function _populateEntryModel()
  {
      $entry = new EntryModel();
  
      // Set section
      $entry->sectionId   = craft()->request->getRequiredPost('sectionId');
      $this->_section     = craft()->sections->getSectionById($entry->sectionId);
      $this->_entryTypeId = craft()->request->getPost('entryTypeId');
  
      // Default
      $entry->authorId    = 1;
      $entry->enabled     = true;
  
      // Set title
      $entry->getContent()->title = craft()->request->getPost('title');
  
      // Set Entry type
      if($this->_entryTypeId)
      {
          $entry->typeId = $this->_entryTypeId;
      }
  
      // Add dynamic fields
      $entry->setContentFromPost(craft()->request->getParam('fields'));
  
      // Return model
      return $entry;
  }
  
  ```
  
  This is how my form looks (I've removed some styling and keept the essentials)
  
  ```
  <form method="post" action="" accept-charset="UTF-8" enctype="multipart/form-data">
  
  <!-- Hidden -->
  {{ getCsrfInput() }}
  <input type="hidden" name="action" value="forms/saveEntry">
  <input type="hidden" name="redirect" value="{{ craft.request.url }}?sent=1">
  <input type="hidden" name="sectionId" value="13">
  <input type="hidden" name="entryTypeId" value="18">
  <input type="hidden" name="title" class="title" value=""/>
  
  <input type="text" name="fields[formName]" value="{% if formEntry.formName is defined %}{{ formEntry.formName }}{% endif %}" class="default-field name" />
  <input type="text" name="fields[formConfirmationNumber]" value="{% if formEntry.formConfirmationNumber is defined %}{{ formEntry.formConfirmationNumber }}{% endif %}" class="default-field" />
  <input type="text" name="fields[formRoom]" value="{% if formEntry.formRoom is defined %}{{ formEntry.formRoom }}{% endif %}" class="default-field" />
  <input type="file" name="fields[formFile]">
  
  </form>
  
  ```
  
  The name="title" field gets set dynamic...
  
  **Tags:** plugin-development, assets
  
  > **Comments:**
  > **username_1**: What does your front-end form look like?  
  > **username_0**: Added it to the original post @username_1.  
  > **username_0**: Also the site uses Craft Pro 2.4.2702. Don't know if that makes a difference.  
  > **username_1**: Hrm... before I setup a test case, any chance you can update to the latest 2.5 to see if it helps?  Lots of enhancement and bug fixes in it.  
  > **username_0**: Since its a quite large site I would like to troubleshoot it as is before running an update. I'm wondering if it has anything to do with me setting the "Entry Type" ID? Because when running it through entries/saveEntry I need to have the targeted "Entry Type" as the root one in the list (it needs to be sorted as default/top entry type in list) since entries/saveEntry doesn't support multiple entry types (I think?). Anything around this we can dig around in @username_1?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-01-18. Score: 1 | Accepted answer
  
  Here's the issue:
  
  ```
  // Add dynamic fields
  $entry->setContentFromPost(craft()->request->getParam('fields'));
  
  ```
  
  [setContentFromPost](https://craftcms.com/classreference/models/BaseElementModel) requires that if you pass any uploaded files in, you need to pass the field name as a string, instead of the actual posted values.
  
  Changing it to this and it should work:
  
  ```
  $entry->setContentFromPost('fields');
  
  ```
  
  
  ---
  
  