コード例 #1
0
 /**
  * @return Response|null
  */
 private function handleGameDetailForm(Request $request, FormInterface $form, GameDetailForm $formObject)
 {
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid() && !$form->get('dealGame')->isClicked()) {
         throw new BadRequestHttpException('invalid or missing submit action');
     }
     if ($form->isSubmitted() && $form->isValid() && $form->get('dealGame')->isClicked()) {
         $this->gameService->deal($formObject->getGameId());
         return $this->redirectToRoute(self::ROUTE_GAME_DETAIL, ['gameId' => $formObject->getGameId()]);
     }
     return;
 }
コード例 #2
0
 /**
  * @param FormInterface $form
  * @return int|false ID of inserted data OR success
  */
 public function registerUser(FormInterface $form)
 {
     if ($this->encoder == null) {
         throw new \Exception("Encoder can not be NULL! Do you added the Encoder by using add_encoder() ??");
     }
     if ($form->isValid()) {
         $data = $form->getData();
         $entity = new GBUserEntry();
         $entity->setNick($data['nick']);
         $entity->setPass($this->encodePassword($entity, $data['password']));
         try {
             $this->emanager->persist($entity);
             $this->emanager->flush();
             return $entity->getUid();
         } catch (\Exception $ex) {
             $this->errormessage = $ex->getMessage();
             if (strstr($this->errormessage, "Duplicate")) {
                 $this->errormessage = "Dieser Nick wird bereits verwendet!";
             }
             return false;
         }
     } elseif ($form->isSubmitted()) {
         $this->errormessage = (string) $form->getErrors(true);
     }
     return false;
 }
 public function handle(FormInterface $form, Request $request)
 {
     $form->handleRequest($request);
     if (!$form->isValid()) {
         return false;
     }
     $data = $form->getData();
     if ($form->isSubmitted()) {
         $user = $this->userManager->findUserByEmail($data['email']);
         if (is_null($user)) {
             $form->addError(new FormError($this->translator->trans('security.resetting.request.errors.email_not_found')));
             return false;
         }
         if ($user->isPasswordRequestNonExpired($this->tokenTll)) {
             $form->addError(new FormError($this->translator->trans('security.resetting.request.errors.password_already_requested')));
             return false;
         }
         if ($user->getConfirmationToken() === null) {
             $user->setConfirmationToken($this->tokenGenerator->generateToken());
         }
         $user->setPasswordRequestedAt(new \DateTime());
         $this->userManager->resettingRequest($user);
     }
     return true;
 }
コード例 #4
0
ファイル: TabType.php プロジェクト: global01/victoire
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $view->vars['valid'] = $valid = !$form->isSubmitted() || $form->isValid();
     $view->vars['icon'] = $valid ? $options['icon'] : $options['error_icon'];
     $view->vars['tab_active'] = false;
     $view->parent->vars['vic_tabbed'] = true;
 }
コード例 #5
0
 /**
  * Adds on constraints found in data class' metadata (yaml/xml/annotations)
  *
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     if (!$form->isSubmitted()) {
         if ($this->metaDataConstraintService instanceof MetaDataConstraintService) {
             $this->metaDataConstraintService->mergeConstraints($form);
         }
     }
 }
コード例 #6
0
 /**
  * @param Request       $request
  * @param FormInterface $form
  *
  * @return Response|null
  */
 private function handleCreateGameForm(Request $request, FormInterface $form, CreateGameForm $formObject)
 {
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $gameId = $this->gameService->createGame($formObject->getName());
         return $this->redirectToRoute(self::ROUTE_GAME_DETAIL, ['gameId' => $gameId]);
     }
     return;
 }
コード例 #7
0
 /**
  * @param FormInterface $form
  */
 private function validateForm(FormInterface $form)
 {
     if (!$form->isSubmitted()) {
         throw new \InvalidArgumentException("FormCriteriaDecorator expects form to be submitted");
     }
     if (!$form->isValid()) {
         throw new \InvalidArgumentException("FormCriteriaDecorator expects form to be valid.");
     }
 }
コード例 #8
0
 /**
  * @param FormInterface $form
  * @param Request $request
  * @return bool
  */
 protected function isFormSubmitted(FormInterface $form, Request $request)
 {
     if ($request->isMethod('POST')) {
         $form->handleRequest($request);
         return $form->isSubmitted();
     } else {
         return false;
     }
 }
コード例 #9
0
 /**
  * @return array|mixed
  */
 protected function getCriteriaFromForm()
 {
     $criteria = [];
     if (null === $this->form) {
         return $criteria;
     }
     $this->form->handleRequest($this->request);
     if ($this->form->isSubmitted() && $this->form->isValid() || !$this->form->isSubmitted()) {
         $criteria = ArrayHelper::arrayForce($this->form->getData());
     }
     return $criteria;
 }
コード例 #10
0
ファイル: EntityFormHandler.php プロジェクト: hogosha/hogosha
 /**
  * @param FormInterface $form
  * @param Request       $request
  *
  * @return mixed|FormInterface
  */
 public function handle(FormInterface $form, Request $request)
 {
     $method = $request->getMethod();
     $form->submit($request, 'PATCH' !== $method);
     if ($form->isSubmitted() && $form->isValid()) {
         $entity = $form->getData();
         $this->registry->getManager()->persist($entity);
         $this->registry->getManager()->flush();
         return $entity;
     }
     return $form;
 }
コード例 #11
0
 /**
  * Gets the registry data given a submitted form.
  * Default configuration is returned if no form provided.
  *
  * @param FormInterface $form
  *
  * @return array
  *
  * @throws RuntimeException
  */
 public function getRegistryData(FormInterface $form = null)
 {
     $data = [];
     if (null !== $form) {
         if (!$form->isSubmitted()) {
             throw new RuntimeException('Form must have been submitted');
         }
         $newData = $form->getData();
         $data = $this->filterNullValues($newData);
     }
     return array_replace_recursive($this->getDefaultData(), $data);
 }
コード例 #12
0
ファイル: PageController.php プロジェクト: teraelis/forum
 /**
  * @param Request       $request
  * @param FormInterface $form
  *
  * @param Page          $page
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
  */
 public function processPageForm(Request $request, $form, $page = null)
 {
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $page = $form->getData();
         $em = $this->get('doctrine.orm.entity_manager');
         $em->persist($page);
         $em->flush();
         return $this->redirect($this->generateUrl('taforum_admin_page', array('pagePermalink' => $page->getPagePermalink())));
     }
     return $this->render('TerAelisForumBundle:Page:admin_page_edit.html.twig', array('page' => !empty($page) ? $page : null, 'form' => $form->createView()));
 }
 /**
  * Render admin form and tag response with status 400 if form is badly completed
  *
  * @param FormInterface $form
  * @param array         $params additional view parameters
  * @param Response|null $response
  * @param string        $template
  *
  * @return Response
  */
 protected function renderAdminForm(FormInterface $form, array $params = array(), $response = null, $template = self::TEMPLATE)
 {
     if (is_null($response)) {
         $code = Response::HTTP_OK;
         if ($form->isSubmitted() && !$form->isValid()) {
             $code = Response::HTTP_UNPROCESSABLE_ENTITY;
         }
         $response = new Response('', $code, array('Content-type' => 'text/html; charset=utf-8'));
     }
     $params = array_merge($params, array('form' => $form->createView()));
     return $this->render($template, $params, $response);
 }
 public function create(FormInterface $form, Request $request)
 {
     $form->handleRequest($request);
     if (!$form->isValid()) {
         return false;
     }
     $entity = $form->getData();
     if ($form->isSubmitted()) {
         if (!is_null($this->manager->checkUniqueEmail($entity->getUser()->getEmail()))) {
             $form->addError(new FormError('Email ja cadastrado!'));
             return false;
         }
     }
     $this->manager->create($entity);
     return true;
 }
コード例 #15
0
 /**
  * @param Request       $request
  * @param FormInterface $form
  * @param GameDetailDto $game
  * @param PlayerDto     $player
  *
  * @return Response|null
  */
 private function handlePlayerForm(Request $request, FormInterface $form, GameDetail $game, Player $player)
 {
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         if ($form->get('play')->isClicked()) {
             $turnNumber = $form->getData()->getTurnNumber();
             $move = $form->getData()->getMove();
             if ($move && $move->isPlay()) {
                 $play = new Play($turnNumber, new Stone($move->getStoneTopValue(), $move->getStoneBottomValue()), $move->getSide() === 'left' ? Play::SIDE_LEFT : Play::SIDE_RIGHT);
                 $this->gameService->play($game->getId(), $player->getNumber(), $play);
                 return $this->redirectToRoute(self::ROUTE_PLAYER_DETAIL, ['gameId' => $form->getData()->getGameId(), 'playerNumber' => $form->getData()->getPlayerNumber()]);
             }
         }
     }
     return;
 }
コード例 #16
0
 /**
  * @param FormInterface $form
  * @return int|false ID of inserted data OR success
  */
 public function addGuestbookEntry(FormInterface $form, $refId = -1)
 {
     if ($form->isValid()) {
         $data = $form->getData();
         return $this->addGuestbookEntryAsData($data['name'], $data['email'], $data['entry'], $refId);
     } elseif ($form->isSubmitted()) {
         $this->errormessage = (string) $form->getErrors(true);
     }
 }
コード例 #17
0
ファイル: PasswordType.php プロジェクト: Ener-Getick/symfony
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     if ($options['always_empty'] || !$form->isSubmitted()) {
         $view->vars['value'] = '';
     }
 }
コード例 #18
0
 /**
  * (non-PHPdoc).
  *
  * @see \ASF\CoreBundle\Form\Handler\FormHandlerInterface::process()
  */
 public function process()
 {
     $this->form->handleRequest($this->request);
     $this->model = $this->form->getData();
     return $this->form->isSubmitted() && $this->form->isValid() && $this->processForm($this->model);
 }
コード例 #19
0
ファイル: ViolationMapper.php プロジェクト: Dren-x/mobit
 /**
  * @param FormInterface $form
  *
  * @return bool
  */
 private function acceptsErrors(FormInterface $form)
 {
     // Ignore non-submitted forms. This happens, for example, in PATCH
     // requests.
     // https://github.com/symfony/symfony/pull/10567
     return $form->isSubmitted() && ($this->allowNonSynchronized || $form->isSynchronized());
 }
コード例 #20
0
ファイル: DiscountFormTabs.php プロジェクト: spryker/Discount
 /**
  * @param \Generated\Shared\Transfer\TabItemTransfer $tabItemTransfer
  * @param string $subForm
  *
  * @return void
  */
 protected function setHasError(TabItemTransfer $tabItemTransfer, $subForm)
 {
     if ($this->discountForm->isSubmitted() && !$this->discountForm->get($subForm)->isValid()) {
         $tabItemTransfer->setHasError(true);
     }
 }
コード例 #21
0
 /**
  * @param FormInterface $form
  * @param $filterData
  * @param $query
  */
 public function applyFilter(FormInterface $form, $filterData, $query)
 {
     $form->submit($filterData);
     if ($form->isSubmitted() && $form->isValid()) {
         $this->eventDispatcher->dispatch(FilterEvent::PRE_FILTER, new FilterEvent($query));
         $this->queryBuilderUpdater->addFilterConditions($form, $query);
     }
 }
コード例 #22
0
ファイル: IndexController.php プロジェクト: spryker/Discount
 /**
  * @param \Symfony\Component\HttpFoundation\Request $request
  * @param \Symfony\Component\Form\FormInterface $discountForm
  *
  * @return void
  */
 protected function handleDiscountForm(Request $request, FormInterface $discountForm)
 {
     $discountForm->handleRequest($request);
     if ($discountForm->isSubmitted()) {
         if ($discountForm->isValid()) {
             $isUpdated = $this->getFacade()->updateDiscount($discountForm->getData());
             if ($isUpdated === true) {
                 $this->addSuccessMessage('Discount successfully updated.');
             }
         } else {
             $this->addErrorMessage('Please fill all required fields.');
         }
     }
 }
コード例 #23
0
ファイル: FormComponent.php プロジェクト: Arachne/Forms
 /**
  * Renders only specified fields. Useful for dynamic ajax forms.
  */
 protected function processRender(FormInterface $form, Request $request)
 {
     $presenter = $this->getPresenter();
     if (!$presenter->isAjax()) {
         throw new BadRequestException('The render signal is only allowed in ajax mode.');
     }
     $fields = $request->getPost($this->lookupPath('Nette\\Application\\UI\\Presenter', true) . self::NAME_SEPARATOR . 'fields');
     if (!$fields) {
         throw new BadRequestException('No fields specified for rendering.');
     }
     $form->handleRequest($request);
     if (!$form->isSubmitted()) {
         throw new BadRequestException('The form was not submitted.');
     }
     $view = $this->getView();
     $widgets = [];
     foreach ($fields as $field) {
         // Validate the field identifier for security reasons. A dot in the identifier would be particularly dangerous.
         if (!Strings::match($field, '~^(?:\\[\\w++\\])++$~')) {
             throw new BadRequestException(sprintf('Field identifier "%s" contains unallowed characters.', $field));
         }
         // Skip duplicates. The renderer would return an empty string on second try.
         if (isset($widgets[$field])) {
             continue;
         }
         // Wrap an exception from PropertyAccessor in a BadRequestException.
         try {
             $fieldView = $this->propertyAccessor->getValue($view, $field);
         } catch (ExceptionInterface $e) {
             throw new BadRequestException(sprintf('FormView not found for field identifier "%s".', $field), 0, $e);
         }
         // Render the field widget.
         $widgets[$field] = $this->renderer->searchAndRenderBlock($fieldView, 'widget');
     }
     $this->getPresenter()->sendJson((object) ['widgets' => $widgets]);
 }
コード例 #24
0
ファイル: FormErrorResolver.php プロジェクト: enhavo/enhavo
 /**
  * @param FormInterface $form
  * @return boolean
  */
 public function isSubmitted(FormInterface $form)
 {
     return $form->isSubmitted();
 }