/**
  * Populate form.
  *
  * @param AmForms_FormModel $form
  * @param array             $formDefinition
  * @param string            $formHandle
  */
 private function populateFormModel(AmForms_FormModel $form, array $formDefinition, $formHandle)
 {
     $form->setAttributes(array('handle' => $formHandle, 'name' => $formDefinition['name'], 'titleFormat' => $form->titleFormat, 'submitAction' => $form->submitAction, 'submitButton' => $form->submitButton, 'afterSubmitText' => $form->afterSubmitText, 'submissionEnabled' => $form->submissionEnabled, 'sendCopy' => $form->sendCopy, 'sendCopyTo' => $form->sendCopyTo, 'notificationEnabled' => $form->notificationEnabled, 'notificationFilesEnabled' => $form->notificationFilesEnabled, 'notificationRecipients' => $form->notificationRecipients, 'notificationSubject' => $form->notificationSubject, 'notificationSenderName' => $form->notificationSenderName, 'notificationReplyToEmail' => $form->notificationReplyToEmail, 'formTemplate' => $form->formTemplate, 'tabTemplate' => $form->tabTemplate, 'fieldTemplate' => $form->fieldTemplate, 'notificationTemplate' => $form->notificationTemplate));
     craft()->content->fieldContext = 'amforms';
     craft()->content->contentTable = 'amforms_content';
     $fieldLayout = craft()->schematic_fields->getFieldLayout($formDefinition['fieldLayout']);
     craft()->content->fieldContext = 'global';
     craft()->content->contentTable = 'content';
     $form->setFieldLayout($fieldLayout);
 }
예제 #2
0
 /**
  * Save a form.
  */
 public function actionSaveForm()
 {
     $this->requirePostRequest();
     // Get form if available
     $formId = craft()->request->getPost('formId');
     if ($formId) {
         $form = craft()->amForms_forms->getFormById($formId);
         if (!$form) {
             throw new Exception(Craft::t('No form exists with the ID “{id}”.', array('id' => $formId)));
         }
     } else {
         $form = new AmForms_FormModel();
     }
     // Field layout
     $fieldLayout = craft()->fields->assembleLayoutFromPost();
     $fieldLayout->type = AmFormsModel::ElementTypeForm;
     $form->setFieldLayout($fieldLayout);
     // Get redirectEntryId
     $redirectEntryId = craft()->request->getPost('redirectEntryId');
     // Form attributes
     $form->redirectEntryId = $redirectEntryId && is_array($redirectEntryId) && count($redirectEntryId) ? $redirectEntryId[0] : null;
     $form->name = craft()->request->getPost('name');
     $form->handle = craft()->request->getPost('handle');
     $form->titleFormat = craft()->request->getPost('titleFormat');
     $form->submitAction = craft()->request->getPost('submitAction');
     $form->submitButton = craft()->request->getPost('submitButton');
     $form->afterSubmitText = craft()->request->getPost('afterSubmitText');
     $form->submissionEnabled = craft()->request->getPost('submissionEnabled');
     $form->sendCopy = craft()->request->getPost('sendCopy');
     $form->sendCopyTo = craft()->request->getPost('sendCopyTo');
     $form->notificationEnabled = craft()->request->getPost('notificationEnabled');
     $form->notificationFilesEnabled = craft()->request->getPost('notificationFilesEnabled');
     $form->notificationRecipients = craft()->request->getPost('notificationRecipients');
     $form->notificationSubject = craft()->request->getPost('notificationSubject');
     $form->notificationSenderName = craft()->request->getPost('notificationSenderName');
     $form->notificationSenderEmail = craft()->request->getPost('notificationSenderEmail');
     $form->notificationReplyToEmail = craft()->request->getPost('notificationReplyToEmail');
     $form->formTemplate = craft()->request->getPost('formTemplate', $form->formTemplate);
     $form->tabTemplate = craft()->request->getPost('tabTemplate', $form->tabTemplate);
     $form->fieldTemplate = craft()->request->getPost('fieldTemplate', $form->fieldTemplate);
     $form->notificationTemplate = craft()->request->getPost('notificationTemplate', $form->notificationTemplate);
     // Save form
     if (craft()->amForms_forms->saveForm($form)) {
         craft()->userSession->setNotice(Craft::t('Form saved.'));
         $this->redirectToPostedUrl($form);
     } else {
         craft()->userSession->setError(Craft::t('Couldn’t save form.'));
         // Send the form back to the template
         craft()->urlManager->setRouteVariables(array('form' => $form));
     }
 }