public function updateAction() { $request = $this->getRequest(); $recipe = $this->readService->findById($this->params('id')); if (false === $this->authorizationService->isGranted('recipe.manage', $recipe)) { throw new UnauthorizedException('Insufficient Permissions'); } $viewModel = new ViewModel(); $viewModel->setTemplate('recipe/update'); $viewModel->setVariables(['form' => $this->form]); $this->form->bind($recipe); if ($request->isPost()) { $this->form->setData($request->getPost()); if ($this->form->isValid()) { try { $this->writeService->save($this->form->getData()); $this->flashMessenger()->addSuccessMessage('Rezept erfolgreich aktualisiert'); $this->redirect()->toRoute('recipe/read/update', ['id' => $this->params('id')]); } catch (\Exception $e) { var_dump($e->getMessage()); } } } $this->layout('layout/backend'); return $viewModel; }
/** * Generate an opening form tag * * @param null|FormInterface $form * @return string */ public function openTag(FormInterface $form = null) { $attributes = array('action' => '', 'method' => 'get'); if ($form instanceof FormInterface) { $formAttributes = $form->getAttributes(); if (array_key_exists('class', $formAttributes) && !empty($formAttributes['class'])) { $formAttributes['class'] = $formAttributes['class'] . ' '; } else { $formAttributes['class'] = ''; } switch ($form->getFormLayout()) { case FormInstance::FORM_LAYOUT_SEARCH: $formAttributes['class'] .= 'form-search'; break; case FormInstance::FORM_LAYOUT_INLINE: $formAttributes['class'] .= 'form-inline'; break; case FormInstance::FORM_LAYOUT_HORIZONTAL: default: $formAttributes['class'] .= 'form-horizontal'; break; } if (!array_key_exists('id', $formAttributes) && array_key_exists('name', $formAttributes)) { $formAttributes['id'] = $formAttributes['name']; } $attributes = array_merge($attributes, $formAttributes); } $tag = sprintf('<form %s>', $this->createAttributesString($attributes)); return $tag; }
public function prepareElement(FormInterface $form) { $form->setAttribute('class', ($this->isMultiple() ? 'multi' : 'single') . '-file-upload'); $form->setAttribute('data-is-empty', null === $this->getValue()); $this->form = $form; parent::prepareElement($form); }
public function indexAction() { $request = $this->getRequest(); $logContent = ''; // initialize when no submit anymore $data = []; $data['logmessage'] = $this->form->get('logmessage')->getValue(); if ($request->isPost()) { $this->form->setData($request->getPost()); if ($this->form->isValid()) { $data = $this->form->getData(); $this->loggerPriority = $data['logpriority']; if ($data['logformat'] !== 'simple') { $this->loggerConfig['writers'][0]['options']['formatter']['name'] = $data['logformat']; unset($this->loggerConfig['writers'][0]['options']['formatter']['options']); } } } $logger = new Logger($this->loggerConfig); // save log data to buffer and make it variable ob_start(); $logger->log((int) $this->loggerPriority, $data['logmessage']); $logContent = ob_get_clean(); return new ViewModel(['form' => $this->form, 'logContent' => $logContent]); }
public function renderAdditional(FormInterface $form, $type) { $result = ''; foreach ($this->contactTypes[$type] as $fieldName => $fieldOptions) { $result .= $this->renderElement($form->get($fieldName), $fieldOptions, true); } return $result; }
public function validate(FormInterface $form, array $data) { $argv = compact('form', 'data'); $this->getEventManager()->trigger(__METHOD__ . '.pre', $this, $argv); $form->setData($data); $isValid = $form->isValid(); $this->getEventManager()->trigger(__METHOD__ . '.post', $this, $argv + array('success' => $isValid)); return $isValid; }
/** * Render a form from the provided $form, * * @param FormInterface $form * @param string $layout * @param array $parameter * @return string */ public function renderBare(FormInterface $form, $layout = self::LAYOUT_INLINE, $parameter = array()) { $renderer = $this->getView(); $headscript = $renderer->plugin('headscript'); $basepath = $renderer->plugin('basepath'); $headscript->appendFile($basepath('Core/js/core.spinnerbutton.js'))->appendFile($basepath('js/select2.min.js'))->appendFile($basepath('Core/js/core.forms.js')); $renderer->headLink()->appendStylesheet($basepath('css/select2.css'))->appendStylesheet($basepath('css/select2-bootstrap.css')); if ($scripts = $form->getOption('headscript')) { if (!is_array($scripts)) { $scripts = array($scripts); } foreach ($scripts as $script) { $headscript->appendFile($basepath($script)); } } $class = $form->getAttribute('class'); $class = preg_replace('~\\bform-[^ ]+\\b~', '', $class); $class .= ' ' . $layout; $form->setAttribute('class', $class); if (method_exists($form, 'prepare')) { $form->prepare(); } $formContent = ''; if ($form instanceof ViewPartialProviderInterface) { return $this->getView()->partial($form->getViewPartial(), array('element' => $form)); } foreach ($form as $element) { $parameterPartial = $parameter; if (!$element->hasAttribute('id')) { $elementId = preg_replace(array('~[^A-Za-z0-9_-]~', '~--+~', '~^-|-$~'), array('-', '-', ''), $form->getName() . '-' . $element->getName()); $element->setAttribute('id', $elementId); } if ($element instanceof ExplicitParameterProviderInterface) { $parameterPartial = array_merge($element->getParams(), $parameterPartial); } if ($element instanceof ViewPartialProviderInterface) { $parameterPartial = array_merge(array('element' => $element, 'layout' => $layout), $parameterPartial); $formContent .= $this->getView()->partial($element->getViewPartial(), $parameterPartial); } else { if ($element instanceof ViewHelperProviderInterface) { $helper = $element->getViewHelper(); if (is_string($helper)) { $helper = $this->getView()->plugin($helper); } $formContent .= $helper($element); } else { if ($element instanceof FieldsetInterface) { $formContent .= $this->getView()->formCollection($element, true, $layout); } else { $formContent .= $this->getView()->formRow($element, null, null, $layout); } } } } return $this->openTag($form) . $formContent . $this->closeTag(); }
/** * @param string $content * @param array $attribs * @param ElementInterface $element * @param FormInterface $form * @return string */ public function render($content, array $attribs = [], ElementInterface $element = null, FormInterface $form = null) { if ($form && $form->hasAttribute('class')) { $class = $form->getAttribute('class'); if (strpos($class, 'form-inline') !== false) { return $content; } } return parent::render($content, $attribs); }
/** * @param FormInterface|null $form */ private function setHorizontal($form) { if ($this->isHorizontal && $form !== null) { if ($form->hasAttribute('class')) { $form->setAttribute('class', 'form-horizontal ' . $form->getAttribute('class')); } else { $form->setAttribute('class', 'form-horizontal'); } } }
public function handle(FormInterface $form, $options = array()) { $options = array_merge($form->getOptions(), $options); if (!isset($options[self::PARSED_FORM_OPTION_KEY])) { $options[self::PARSED_FORM_OPTION_KEY] = new \FzyForm\Annotation\Form($form, $this->getServiceLocator()->get('FzyCommon\\Service\\EntityToForm')); $form->setOptions($options); } /* @var $annotated \FzyForm\Annotation\Form */ $annotated = $options[self::PARSED_FORM_OPTION_KEY]; return $this->getServiceLocator()->get('FzyCommon\\Render')->handle($annotated->getTemplate(), array('element' => $annotated, 'options' => $options)); }
/** * Generate an opening form tag * * @param null|FormInterface $form * @return string */ public function openTag(FormInterface $form = null) { $attributes = array('action' => '', 'method' => 'get'); if ($form instanceof FormInterface) { $formAttributes = $form->getAttributes(); if (!array_key_exists('id', $formAttributes) && array_key_exists('name', $formAttributes)) { $formAttributes['id'] = $formAttributes['name']; } $attributes = array_merge($attributes, $formAttributes); } return sprintf('<form %s>', $this->createAttributesString($attributes)); }
public function createAction() { if ($this->getRequest()->isPost()) { $this->dashboardForm->setData($this->getRequest()->getPost()); if ($this->dashboardForm->isValid()) { $data = $this->dashboardForm->getData(); $this->dashboardTaskService->persistFromArray($data); return $this->redirect()->toRoute('dashboard/manage'); } } return new ViewModel(['dashboardForm' => $this->dashboardForm]); }
/** * Sets form layout class * * @param FormInterface $oForm * @param string $sFormLayout * @return void */ protected function setFormClass(FormInterface $oForm, $sFormLayout = self::LAYOUT_HORIZONTAL) { if (is_string($sFormLayout)) { $sLayoutClass = 'form-' . $sFormLayout; if ($sFormClass = $oForm->getAttribute('class')) { if (!preg_match('/(\\s|^)' . preg_quote($sLayoutClass, '/') . '(\\s|$)/', $sFormClass)) { $oForm->setAttribute('class', trim($sFormClass . ' ' . $sLayoutClass)); } } else { $oForm->setAttribute('class', $sLayoutClass); } } }
/** * * @return ViewModel|Response */ public function indexAction() { if (!is_null($this->identity())) { return $this->redirect()->toRoute($this->loginRedirectRoute); } if ($this->getRequest()->isPost()) { $this->loginForm->setData($this->getRequest()->getPost()); if ($this->loginForm->isValid()) { return $this->redirect()->toRoute($this->loginRedirectRoute); } } return new ViewModel(array('loginForm' => $this->loginForm)); }
public function indexAction() { $request = $this->getRequest(); $formMessages = []; $isPost = false; if ($request->isPost()) { $this->form->setData($request->getPost()); $this->form->isValid(); $formMessages = $this->form->getMessages(); $isPost = true; } return new ViewModel(['form' => $this->form, 'formMessages' => $formMessages, 'isPost' => $isPost]); }
public function editPageRepository(FormInterface $form) { $page = $form->getObject(); if (!$form->isValid()) { throw new RuntimeException(print_r($form->getMessages(), true)); } $data = $form->getData(FormInterface::VALUES_AS_ARRAY); $formClone = clone $form; $formClone->bind($page); $formClone->setData($data); $formClone->isValid(); $this->assertGranted('page.update', $page); $this->getObjectManager()->persist($page); return $page; }
public function indexAction() { $this->settingsForm->setData($this->settingsManager->getAll()); if ($this->getRequest()->isPost()) { $this->settingsForm->setData($this->getRequest()->getPost()); if ($this->settingsForm->isValid()) { $data = $this->settingsForm->getData(); $this->settingsManager->set('application_title', $data['application_title']); $this->settingsManager->flush(); $this->flashMessenger()->addSuccessMessage('The settings have been saved.'); return $this->redirect()->toRoute('admin/system/settings'); } } return new ViewModel(['settingsForm' => $this->settingsForm]); }
public function updateAction() { $person = $this->contactService->findPerson($this->params('id')); if (!$person) { return $this->notFoundAction(); } $this->contactForm->bind($person); if ($this->getRequest()->isPost()) { $this->contactForm->setData($this->getRequest()->getPost()); if ($this->contactForm->isValid()) { $person = $this->contactService->persistContact($this->contactForm->getData()); return $this->redirect()->toRoute('contacts/view', ['type' => ContactEntry::TYPE_PERSON, 'id' => $person->getId()->toString()]); } } return new ViewModel(['person' => $person, 'contactForm' => $this->contactForm]); }
/** * Use the form to get barcode image from selected barcode object. */ public function indexAction() { $request = $this->getRequest(); //default value without post parameter $barcodeOptions = ['text' => '123456789']; $barcode = Barcode::factory('codabar', 'image', $barcodeOptions); if ($request->isPost()) { $this->form->setData($request->getPost()); if ($this->form->isValid()) { $barcodeOptions = ['text' => $this->form->getData()['barcode-object-text']]; $barcode = Barcode::factory($this->form->getData()['barcode-object-select'], 'image', $barcodeOptions); } } imagegif($barcode->draw(), './data/barcode.gif'); return new ViewModel(['form' => $this->form]); }
public function changesAction() { $siteId = $this->services->getUtilityService()->getSiteId(); $site = $this->services->getSiteService()->find($siteId); $fromControl = $this->dateIntervalForm->get(DateIntervalForm::FROM_DATE_NAME); $toControl = $this->dateIntervalForm->get(DateIntervalForm::TO_DATE_NAME); $lastDate = $site->getLastUpdate(); $lastDate->setTime(23, 59, 59); $fromControl->setAttribute('max', $lastDate->format('Y-m-d')); $toControl->setAttribute('max', $lastDate->format('Y-m-d')); $from = clone $lastDate; $from->sub(new \DateInterval('P1M')); $to = $lastDate; $fromControl->setValue($from->format('Y-m-d')); $toControl->setValue($to->format('Y-m-d')); $request = $this->getRequest(); if ($request->isPost()) { $this->dateIntervalForm->setData($request->getPost()); if ($this->dateIntervalForm->isValid()) { $from = \DateTime::createFromFormat('Y-m-d', $fromControl->getValue()); $to = \DateTime::createFromFormat('Y-m-d', $toControl->getValue()); } } $from->setTime(0, 0, 0); $to->setTime(23, 59, 59); $result = array('intervalForm' => $this->dateIntervalForm, 'site' => $site, 'members' => $this->getMembersData($siteId, $from, $to), 'pages' => $this->getPagesData($siteId, $from, $to), 'revisions' => $this->getRevisionsData($siteId, $from, $to), 'votes' => $this->getVotesData($siteId, $from, $to)); return new ViewModel($result); }
public function resetPasswordAction() { $code = $this->params('code'); if ($code) { $this->resetPasswordForm->get('code')->setValue($code); } if ($this->getRequest()->isPost()) { $this->resetPasswordForm->setData($this->getRequest()->getPost()); if ($this->resetPasswordForm->isValid()) { $data = $this->resetPasswordForm->getData(); $this->passwordChanger->resetAccountPassword($data['code'], $data['credential']); return $this->redirect()->toRoute('login'); } } return new ViewModel(['resetPasswordForm' => $this->resetPasswordForm, 'code' => $code]); }
public function updateAction() { $company = $this->contactService->findCompany($this->params('id')); if (!$company) { return $this->notFoundAction(); } $this->contactForm->bind($company); if ($this->getRequest()->isPost()) { $this->contactForm->setData($this->getRequest()->getPost()); if ($this->contactForm->isValid()) { $company = $this->contactService->persistContact($this->contactForm->getData()); return $this->redirect()->toRoute('contacts/view', ['type' => ContactEntry::TYPE_COMPANY, 'id' => $company->getId()->toString()]); } } return new ViewModel(['company' => $company, 'contactForm' => $this->contactForm]); }
public function createRole(FormInterface $form) { $this->assertGranted('authorization.role.create'); if (!$form->isValid()) { throw new RuntimeException(print_r($form->getMessages(), true)); } $processingForm = clone $form; $data = $processingForm->getData(FormInterface::VALUES_AS_ARRAY); $processingForm->bind(new Role()); $processingForm->setData($data); if (!$processingForm->isValid()) { throw new RuntimeException(print_r($processingForm->getMessages(), true)); } $this->objectManager->persist($processingForm->getObject()); return $processingForm->getObject(); }
public function updateAction() { $cronjob = $this->cronManager->find($this->params('id')); if (!$cronjob) { return $this->notFoundAction(); } $this->cronjobForm->bind($cronjob); if ($this->getRequest()->isPost()) { $this->cronjobForm->setData($this->getRequest()->getPost()); if ($this->cronjobForm->isValid()) { $data = $this->cronjobForm->getData(); $this->cronManager->persist($data); return $this->redirect()->toRoute('admin/system/cron'); } } return new ViewModel(['cronjob' => $cronjob, 'cronjobForm' => $this->cronjobForm]); }
public function indexAction() { if ($this->getRequest()->isPost()) { $this->installForm->setData(array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray())); if ($this->installForm->isValid()) { $data = $this->installForm->getData(); if ($data['plugin']['error'] === 0) { $this->pluginManager->installFile($data['plugin']['tmp_name']); } else { $this->pluginManager->installExternal($data['location']); } $this->flashMessenger()->addSuccessMessage('The plugin has been installed.'); return $this->redirect()->toRoute('admin/system/plugins'); } } return new ViewModel(['plugins' => $this->pluginManager->getPlugins(), 'installForm' => $this->installForm]); }
public function editAction() { $client = $this->clientRepository->find($this->params('clientId')); if ($client === null) { $this->getResponse()->setStatusCode(404); return; } $this->clientForm->bind($client); if ($this->getRequest()->isPost()) { $this->clientForm->setData($this->getRequest()->getPost()); if ($this->clientForm->isValid()) { $this->clientService->persist($this->clientForm->getData()); $this->redirect()->toRoute('clients/show', ['clientId' => $client->getId()]); } } return new ViewModel(['form' => $this->clientForm]); }
/** * Render single element * * @access public * @param FormInterface $form * @param Zend\Form\Element $element * @return string element HTML content */ public function renderElement($form, $element) { $inlineForm = false; if (strpos($form->getAttribute('class'), "form-horizontal") === false) { $inlineForm = true; } $elementContent = ''; // add required class to all required elements if (!empty($element->getAttribute('required')) && !$element->getLabelOption("disable_html_escape")) { $labelAttributes = $element->getLabelAttributes(); $labelClass = isset($labelAttributes["class"]) ? $labelAttributes["class"] : ""; $labelAttributes["class"] = $labelClass . " required"; $element->setLabelAttributes($labelAttributes); } // Add Id to all form elements // When element has an Id, Label tag won't enclose form element if (empty($element->getAttribute('id'))) { $element->setAttribute('id', $form->getAttribute('name') . "_" . $element->getAttribute('name')); } $labelAbsent = false; $formElementAppendString = ''; if (empty($element->getLabel()) && $element->getAttribute('type') !== "hidden") { $labelAbsent = true; } if ($labelAbsent === true && (strpos($element->getAttribute('class'), "btn") === false || strpos($element->getAttribute('class'), "btn") !== false && strpos($element->getAttribute('class'), "pull") === false) && $inlineForm === false) { $elementContent .= "<dt> </dt>"; } else { $divAttributes = ""; if ($inlineForm === true) { $divAttributes = "class='form-group'"; } $elementContent .= "<div {$divAttributes} >"; $formElementAppendString = '</div>'; } // Change submit button text to edit if form is an edit form if ($element instanceof Submit && $form->isEditForm === true) { if (property_exists($form, "isAdminUser") && $form->isAdminUser === false && $form->needAdminApproval === true) { $element->setValue(FormButtons::SUBMIT_FOR_ADMIN_APPROVAL_BUTTON_TEXT); } elseif ($element->getValue() == FormButtons::CREATE_BUTTON_TEXT) { $element->setValue(FormButtons::EDIT_BUTTON_TEXT); } } $elementContent .= $this->getView()->formRow($element); $elementContent .= $formElementAppendString; return $elementContent; }
/** * @return \Zend\Http\Response|ViewModel */ public function editAction() { $request = $this->getRequest(); $post = $this->postService->findPost($this->params('id')); $this->postForm->bind($post); if ($request->isPost()) { $this->postForm->setData($request->getPost()); if ($this->postForm->isValid()) { try { $this->postService->savePost($this->postForm->getData()); return $this->redirect()->toRoute('blog'); } catch (\Exception $e) { } } } return new ViewModel(array('form' => $this->postForm)); }
public function render(FormInterface $form, $colMap = null, $buttonsSpan = null) { $headscript = $this->getView()->plugin('headscript'); $basepath = $this->getView()->plugin('basepath'); $headscript->appendFile($basepath('Core/js/core.searchform.js')); if (is_int($colMap)) { $buttonsSpan = $colMap; $colMap = null; } if ($form instanceof ViewPartialProviderInterface) { return $this->getView()->partial($form->getViewPartial(), ['element' => $form, 'colMap' => $colMap, 'buttonsSpan' => $buttonsSpan]); } $elements = $form->getElements(); $buttons = $form->getButtons(); $content = $this->renderElements($elements, $buttons, $colMap, $buttonsSpan); return $this->openTag($form) . '<div class="row" style="padding: 0 15px;">' . $content . '</div>' . $this->closeTag(); }
/** * Outputs message depending on flag * * @param FormInterface $form * @param array $staticElements * @param null $formClass * * @return string */ public function __invoke(FormInterface $form, array $staticElements = [], $formClass = null) { $submitElements = []; /** @var Form $form */ $form->setAttribute('role', 'form'); if ($formClass == 'form-inline') { $form->setAttribute('class', $formClass . ' pull-right'); } elseif ($formClass) { $form->setAttribute('class', $formClass); } else { $formClass = $form->getAttribute('class'); } $form->prepare(); $output = $this->getView()->form()->openTag($form); foreach ($staticElements as $element) { $viewModel = new ViewModel(); $viewModel->setVariable('label', $element['label']); $viewModel->setVariable('value', $element['value']); $viewModel->setTemplate('travello-view-helper/widget/bootstrap-form-static'); $output .= $this->getView()->render($viewModel); } list($output, $submitElements) = $this->renderElements($form, $formClass, $output, $submitElements); if ($formClass == 'form-inline') { $template = 'bootstrap-form-submit-inline'; } else { $template = 'bootstrap-form-submit'; } $viewModel = new ViewModel(); $viewModel->setVariable('submitElements', $submitElements); $viewModel->setTemplate('travello-view-helper/widget/' . $template); $output .= $this->getView()->render($viewModel); $output .= $this->getView()->form()->closeTag(); return $output; }