/** * Save a form submission by Angular. */ public function actionSaveSubmissionByAngular() { $this->requirePostRequest(); $this->requireAjaxRequest(); // Get the form $handle = craft()->request->getRequiredParam('handle'); $form = craft()->amForms_forms->getFormByHandle($handle); if (!$form) { throw new Exception(Craft::t('No form exists with the handle “{handle}”.', array('handle' => $handle))); } // Get the submission $submission = new AmForms_SubmissionModel(); // Add the form to the submission $submission->form = $form; $submission->formId = $form->id; // Set attributes $fieldsLocation = craft()->request->getParam('fieldsLocation', 'fields'); $fieldsContent = json_decode(craft()->request->getParam($fieldsLocation), true); $submission->ipAddress = craft()->request->getUserHostAddress(); $submission->userAgent = craft()->request->getUserAgent(); $submission->setContentFromPost($fieldsContent); $submission->setContentPostLocation($fieldsLocation); // Upload possible files foreach ($form->getFieldLayout()->getTabs() as $tab) { // Tab fields $fields = $tab->getFields(); foreach ($fields as $layoutField) { // Get actual field $field = $layoutField->getField(); // Look for possible file if ($field->type == 'Assets') { $this->_uploadFilesForField($field, $submission, $fieldsContent); } } } // Save submission if (craft()->amForms_submissions->saveSubmission($submission)) { // Notification craft()->amForms_submissions->emailSubmission($submission); // Response $this->returnJson(array('success' => true)); } else { $return = array('success' => false, 'errors' => $submission->getErrors()); $this->returnJson($return); } }