/**
  * Saves a form
  */
 public function actionSaveForm()
 {
     $this->requirePostRequest();
     $form = new Applications_FormModel();
     // Shared attributes
     $form->id = craft()->request->getPost('formId');
     $form->name = craft()->request->getPost('name');
     $form->handle = craft()->request->getPost('handle');
     // Set the field layout
     $fieldLayout = craft()->fields->assembleLayoutFromPost();
     $fieldLayout->type = ElementType::Asset;
     $form->setFieldLayout($fieldLayout);
     // Save it
     if (craft()->applications_forms->saveForm($form)) {
         craft()->userSession->setNotice(Craft::t('Form saved.'));
         $this->redirectToPostedUrl($form);
     } else {
         craft()->userSession->setError(Craft::t('Couldn’t save the form.'));
     }
     // Send the form back to the template
     craft()->urlManager->setRouteVariables(array('form' => $form));
 }