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...