I have a custom element type that I want to allow anonymous submission from the front-end. I have a solid concept on how the form data is passed but I seem to be missing something.
I have the controller setup like so:
class PluginNameController extends BaseController
{
/**
* @var Allows anonymous access to this controller's actions.
* @access protected
*/
protected $allowAnonymous = array('actionSubmit');
/**
* Allow public submission of the element type
*/
public function actionSubmit()
{
// require post request for this action
$this->requirePostRequest();
$entry = craft()->request->getPost();
// set the form id from the post request
$formId = craft()->request->getPost('formId');
$entry = craft()->request->getPost();
// if form id is empty, throw exception as we can't continue
if (!$formId) {
throw new Exception(Craft::t('The formId is required to submit.'));
}
if (craft()->pluginName->publicSubmission($formId, $entry))
{
$this->redirectToPostedUrl();
}
else
{
die('failed submission');
}
}
My element type has 4 fields that are required and those submit anonymously as expected as I am grabbing them using getPost
. However, my plugin also utilizes the getSources
method and each formId
has a field layout assigned to the custom element type, lets say 'entry'.
Whats causing the trip up is the fact that since this is an element type that utilizes a field layout, I will need to account for the fields based on the formId
. So when using getPost
I can namespace the attributes for the element type, but I am trying to find the best way to capture the fields specified in the field layout and save those to the appropriate table..
Any thoughts?
craft()->fields->assembleLayoutFromPost();
and seeing how far that gets me.