public function testArrayAccess() { $postData = $this->formData(); $formData = new FormData($postData['testing_form']); $this->assertNull($formData->offsetSet('test', true)); $this->assertTrue($formData->offsetExists('name')); $this->assertSame('Gawain Lynch', $formData->offsetGet('name')); $this->assertNull($formData->offsetUnset('test')); }
/** * Get a resolved field value. * * If the form notification configuration wants a value to be returned from * a submitted field we use this, otherwise the configured parameter. * * @param string $value */ private function getConfigValue($value) { if ($this->formData->has($value)) { return $this->formData->get($value); } return $value; }
/** * 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]); } }
/** * Build a GET query if required. * * @param array $redirect * @param FormData $formData * * @return string */ protected function getRedirectQuery(array $redirect, FormData $formData) { if (!isset($redirect['query']) || empty($redirect['query'])) { return ''; } $query = array(); if (is_array($redirect['query'])) { if (Arr::isIndexedArray($redirect['query'])) { foreach ($redirect['query'] as $param) { $query[$param] = $formData->get($param); } } else { foreach ($redirect['query'] as $id => $param) { $query[$id] = $formData->get($param); } } } else { $param = $redirect['query']; $query[$param] = $formData->get($param); } return '?' . http_build_query($query); }
/** * 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; }
/** * 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'])); } } }