Beispiel #1
0
 /**
  * Write out form data to a specified contenttype table
  *
  * @param string   $contenttype
  * @param FormData $formData
  */
 public function writeToContentype($contenttype, FormData $formData)
 {
     // Get an empty record for out contenttype
     $record = $this->app['storage']->getEmptyContent($contenttype);
     // Set a published date
     if (!$formData->has('datepublish')) {
         $formData->set('datepublish', date('Y-m-d H:i:s'));
     }
     foreach ($formData->keys() as $name) {
         // Store the data array into the record
         $record->setValue($name, $formData->get($name, true));
     }
     try {
         $this->app['storage']->saveContent($record);
     } catch (\Exception $e) {
         $this->app['logger.system']->critical("[Bolt Forms] An exception occurred saving submission to ContentType table `{$contenttype}`", ['event' => 'extensions', 'exception' => $e]);
     }
 }
Beispiel #2
0
 /**
  * Get the data suitable for using in TWig.
  *
  * @param EmailConfig $emailConfig
  * @param FormData    $formData
  *
  * @return array
  */
 private function getBodyData(EmailConfig $emailConfig, FormData $formData)
 {
     $bodydata = array();
     foreach ($formData->keys() as $key) {
         if ($formData->get($key) instanceof FileUpload) {
             if ($formData->get($key)->isValid() && $emailConfig->attachFiles()) {
                 $attachment = \Swift_Attachment::fromPath($formData->get($key)->fullPath())->setFilename($formData->get($key)->getFile()->getClientOriginalName());
                 $this->message->attach($attachment);
             }
         } else {
             $bodydata[$key] = $formData->get($key, true);
         }
     }
     return $bodydata;
 }
Beispiel #3
0
 /**
  * Process the fields to get usable data.
  *
  * @param FormConfig $formConfig
  * @param FormData   $formData
  *
  * @throws FileUploadException
  */
 protected function processFields(FormConfig $formConfig, FormData $formData)
 {
     foreach ($formData->keys() as $fieldName) {
         $field = $formData->get($fieldName);
         // Handle file uploads
         if ($field instanceof UploadedFile) {
             if (!$field->isValid()) {
                 throw new FileUploadException($field->getErrorMessage());
             }
             // Get the upload object
             $formData->set($fieldName, new FileUpload($this->app, $formConfig->getName(), $field));
             if (!$this->config['uploads']['enabled']) {
                 $this->app['logger.system']->debug('[BoltForms] File upload skipped as the administrator has disabled uploads for all forms.', ['event' => 'extensions']);
                 continue;
             }
             // Take configured actions on the file
             $formData->get($fieldName)->move();
         }
         // Handle events for custom data
         $fieldConf = $formConfig->getFields()->{$fieldName}();
         if (isset($fieldConf['event']['name'])) {
             $formData->set($fieldName, $this->dispatchCustomDataEvent($fieldConf['event']));
         }
     }
 }