当前位置: 首页>>代码示例>>PHP>>正文


PHP FormInterface::addError方法代码示例

本文整理汇总了PHP中Symfony\Component\Form\FormInterface::addError方法的典型用法代码示例。如果您正苦于以下问题:PHP FormInterface::addError方法的具体用法?PHP FormInterface::addError怎么用?PHP FormInterface::addError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Form\FormInterface的用法示例。


在下文中一共展示了FormInterface::addError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: handle

 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;
 }
开发者ID:neandher,项目名称:Symfony-Multiple-Authentication,代码行数:25,代码来源:ResettingRequestFormHandler.php

示例2: validate

    public function validate(FormInterface $form)
    {
        if (!$form->isSynchronized()) {
            $form->addError(new FormError('The value is invalid'));
        }

        if (count($form->getExtraData()) > 0) {
            $form->addError(new FormError('This form should not contain extra fields'));
        }

        if ($form->isRoot() && isset($_SERVER['CONTENT_LENGTH'])) {
            $length = (int) $_SERVER['CONTENT_LENGTH'];
            $max = trim(ini_get('post_max_size'));

            switch (strtolower(substr($max, -1))) {
                // The 'G' modifier is available since PHP 5.1.0
                case 'g':
                    $max *= 1024;
                case 'm':
                    $max *= 1024;
                case 'k':
                    $max *= 1024;
            }

            if ($length > $max) {
                $form->addError(new FormError('The uploaded file was too large. Please try to upload a smaller file'));
            }
        }
    }
开发者ID:nacef,项目名称:symfony,代码行数:29,代码来源:DefaultValidator.php

示例3: process

 /**
  * Process form
  *
  * @param  EmailTemplate $entity
  *
  * @return bool True on successful processing, false otherwise
  */
 public function process(EmailTemplate $entity)
 {
     // always use default locale during template edit in order to allow update of default locale
     $entity->setLocale($this->defaultLocale);
     if ($entity->getId()) {
         // refresh translations
         $this->manager->refresh($entity);
     }
     $this->form->setData($entity);
     if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
         // deny to modify system templates
         if ($entity->getIsSystem() && !$entity->getIsEditable()) {
             $this->form->addError(new FormError($this->translator->trans('oro.email.handler.attempt_save_system_template')));
             return false;
         }
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             // mark an email template creating by an user as editable
             if (!$entity->getId()) {
                 $entity->setIsEditable(true);
             }
             $this->manager->persist($entity);
             $this->manager->flush();
             return true;
         }
     }
     return false;
 }
开发者ID:Maksold,项目名称:platform,代码行数:35,代码来源:EmailTemplateHandler.php

示例4: process

 /**
  * Prepare & process form
  *
  * @author Jeremie Samson <jeremie@ylly.fr>
  *
  * @return bool
  */
 public function process()
 {
     if ($this->request->isMethod('POST')) {
         $this->form->handleRequest($this->request);
         if ($this->form->isValid()) {
             /** @var ModelUserRole $model */
             $model = $this->form->getData();
             if (!$model->getUser() || !$model->getRole()) {
                 $this->form->addError(new FormError('Missing parameter(s)'));
             }
             /** @var User $user */
             $user = $this->em->getRepository('UserBundle:User')->find($model->getUser());
             /** @var Post $role */
             $role = $this->em->getRepository('FaucondorBundle:Post')->find($model->getRole());
             if (!$user) {
                 $this->form->get('user')->addError(new FormError('User with id ' . $model->getUser() . ' not found '));
             }
             if (!$role) {
                 $this->form->get('role')->addError(new FormError('Role with id ' . $model->getRole() . ' not found '));
             }
             $this->onSuccess($user, $role);
             return true;
         }
     }
     return false;
 }
开发者ID:ESNFranceG33kTeam,项目名称:sf_faucondor,代码行数:33,代码来源:UserRoleHandler.php

示例5: process

 /**
  * Prepare & process form
  *
  * @author Jeremie Samson <jeremie@ylly.fr>
  *
  * @return bool
  */
 public function process()
 {
     if ($this->request->isMethod('POST')) {
         $this->form->handleRequest($this->request);
         if ($this->form->isValid()) {
             /** @var ModelUser $user */
             $user = $this->form->getData();
             if (!$user->getFirstname() || !$user->getLastname() || !$user->getEmailGalaxy() || !$user->getSection()) {
                 $this->form->addError(new FormError('Missing parameter(s)'));
             } else {
                 if (!filter_var($user->getEmail(), FILTER_VALIDATE_EMAIL) || !filter_var($user->getEmailGalaxy(), FILTER_VALIDATE_EMAIL)) {
                     $error = new FormError('email invalid');
                     if (!filter_var($user->getEmail(), FILTER_VALIDATE_EMAIL)) {
                         $this->form->get('email')->addError($error);
                     }
                     if (!filter_var($user->getEmailGalaxy(), FILTER_VALIDATE_EMAIL)) {
                         $this->form->get('emailGalaxy')->addError($error);
                     }
                 } else {
                     $section_id = $this->em->getRepository('FaucondorBundle:Section')->find($user->getSection());
                     $section_code = $this->em->getRepository('FaucondorBundle:Section')->findOneBy(array("code" => $user->getSection()));
                     if (!$section_id && !$section_code) {
                         $this->form->get('section')->addError(new FormError('Section with id ' . $user->getSection() . ' not found'));
                     } else {
                         /** @var Section $section */
                         $section = $section_id ? $section_id : $section_code;
                         $this->onSuccess($user, $section);
                         return true;
                     }
                 }
             }
         }
     }
     return false;
 }
开发者ID:ESNFranceG33kTeam,项目名称:sf_faucondor,代码行数:42,代码来源:UserHandler.php

示例6: validate

 public function validate(Form\FormInterface $form)
 {
     $discountAmounts = false;
     foreach ($form->get('discountAmounts')->getData() as $currency => $amount) {
         if ($amount) {
             $discountAmounts = true;
             break;
         }
     }
     if ($form->get('percentage')->getData() && $discountAmounts) {
         $form->addError(new Form\FormError('Please only fill in either a percentage OR a fixed discount.'));
     } elseif (!$form->get('percentage')->getData() && !$discountAmounts && false === $form->get('freeShipping')->getData()) {
         $form->addError(new Form\FormError('Neither a percentage discount, nor a fixed discount amount, nor free shipping have been added to this discount.'));
     }
 }
开发者ID:mothership-ec,项目名称:cog-mothership-discount,代码行数:15,代码来源:DiscountBenefitForm.php

示例7: handleRequest

 /**
  * {@inheritdoc}
  */
 public function handleRequest(FormInterface $form, $request = null)
 {
     if (null !== $request) {
         throw new UnexpectedTypeException($request, 'null');
     }
     $name = $form->getName();
     $method = $form->getConfig()->getMethod();
     if ($method !== self::getRequestMethod()) {
         return;
     }
     // For request methods that must not have a request body we fetch data
     // from the query string. Otherwise we look for data in the request body.
     if ('GET' === $method || 'HEAD' === $method || 'TRACE' === $method) {
         if ('' === $name) {
             $data = $_GET;
         } else {
             // Don't submit GET requests if the form's name does not exist
             // in the request
             if (!isset($_GET[$name])) {
                 return;
             }
             $data = $_GET[$name];
         }
     } else {
         // Mark the form with an error if the uploaded size was too large
         // This is done here and not in FormValidator because $_POST is
         // empty when that error occurs. Hence the form is never submitted.
         if ($this->serverParams->hasPostMaxSizeBeenExceeded()) {
             // Submit the form, but don't clear the default values
             $form->submit(null, false);
             $form->addError(new FormError($form->getConfig()->getOption('post_max_size_message'), null, array('{{ max }}' => $this->serverParams->getNormalizedIniPostMaxSize())));
             return;
         }
         $fixedFiles = array();
         foreach ($_FILES as $fileKey => $file) {
             $fixedFiles[$fileKey] = self::stripEmptyFiles(self::fixPhpFilesArray($file));
         }
         if ('' === $name) {
             $params = $_POST;
             $files = $fixedFiles;
         } elseif (array_key_exists($name, $_POST) || array_key_exists($name, $fixedFiles)) {
             $default = $form->getConfig()->getCompound() ? array() : null;
             $params = array_key_exists($name, $_POST) ? $_POST[$name] : $default;
             $files = array_key_exists($name, $fixedFiles) ? $fixedFiles[$name] : $default;
         } else {
             // Don't submit the form if it is not present in the request
             return;
         }
         if (is_array($params) && is_array($files)) {
             $data = array_replace_recursive($params, $files);
         } else {
             $data = $params ?: $files;
         }
     }
     // Don't auto-submit the form unless at least one field is present.
     if ('' === $name && count(array_intersect_key($data, $form->all())) <= 0) {
         return;
     }
     $form->submit($data, 'PATCH' !== $method);
 }
开发者ID:unexge,项目名称:symfony,代码行数:63,代码来源:NativeRequestHandler.php

示例8: translate

 /**
  * Bind all errors from ApiClientException $e to $form.
  *
  * You can override mapping between parameters in ApiClientException::getError
  * and parameters in FormInterface by giving a $map.
  * If string association is not enough, you can use a callable to
  * return a sub-form:
  *
  *   ->translate($form, $e, array(
  *       'password' => function($form) { return $form->get('rawPassword')->get('first'); },
  *       'foo'      => 'bar',
  *   ))
  *
  * @param FormInterface       $form The form
  * @param ApiClientException  $e    The exception
  * @param string[]|callable[] $map  The mapping between api parameters and form parameters
  *
  * @return FormInterface The form
  */
 public function translate(FormInterface $form, ApiClientException $e, array $map = array())
 {
     if (!$e->getError()) {
         $form->addError(new FormError($e->getMessage()));
         return $form;
     }
     foreach ($e->getError()->getEntityBodyParameters() as $parameterName => $messages) {
         $widget = $form;
         if (array_key_exists($parameterName, $map)) {
             if (is_callable($map[$parameterName])) {
                 $widget = $map[$parameterName]($form);
                 if (!$widget instanceof FormInterface) {
                     throw new \LogicException(sprintf('The callable ("$map[%s]") should return a FormInterface', $parameterName));
                 }
             } else {
                 $widget = $form->get($map[$parameterName]);
             }
         } elseif ($form->has($parameterName)) {
             $widget = $form->get($parameterName);
         }
         foreach ($messages as $message) {
             if (null === $widget->getParent()) {
                 $widget->addError(new FormError(sprintf('%s: %s', $parameterName, $message)));
             } else {
                 $widget->addError(new FormError($message));
             }
         }
     }
     return $form;
 }
开发者ID:KinaMarie,项目名称:connect,代码行数:49,代码来源:ErrorTranslator.php

示例9: addError

 /**
  * Adds an error to the field.
  *
  * @see FormInterface
  */
 public function addError(FormError $error)
 {
     if ($this->parent && $this->errorBubbling) {
         $this->parent->addError($error);
     } else {
         $this->errors[] = $error;
     }
 }
开发者ID:nacef,项目名称:symfony,代码行数:13,代码来源:Form.php

示例10: process

 /**
  * Process form
  *
  * @param  Email $model
  * @return bool True on successful processing, false otherwise
  */
 public function process(Email $model)
 {
     $this->form->setData($model);
     if (in_array($this->request->getMethod(), ['POST', 'PUT'])) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             try {
                 $this->emailProcessor->process($model);
                 return true;
             } catch (\Exception $ex) {
                 $this->logger->error('Email sending failed.', ['exception' => $ex]);
                 $this->form->addError(new FormError($ex->getMessage()));
             }
         }
     }
     return false;
 }
开发者ID:Maksold,项目名称:platform,代码行数:23,代码来源:EmailHandler.php

示例11: handleRequest

 /**
  * {@inheritdoc}
  */
 public function handleRequest(FormInterface $form, $request = null)
 {
     if (!$request instanceof Request) {
         throw new UnexpectedTypeException($request, 'Symfony\\Component\\HttpFoundation\\Request');
     }
     $name = $form->getName();
     $method = $form->getConfig()->getMethod();
     if ($method !== $request->getMethod()) {
         return;
     }
     // For request methods that must not have a request body we fetch data
     // from the query string. Otherwise we look for data in the request body.
     if ('GET' === $method || 'HEAD' === $method || 'TRACE' === $method) {
         if ('' === $name) {
             $data = $request->query->all();
         } else {
             // Don't submit GET requests if the form's name does not exist
             // in the request
             if (!$request->query->has($name)) {
                 return;
             }
             $data = $request->query->get($name);
         }
     } else {
         // Mark the form with an error if the uploaded size was too large
         // This is done here and not in FormValidator because $_POST is
         // empty when that error occurs. Hence the form is never submitted.
         $contentLength = $this->serverParams->getContentLength();
         $maxContentLength = $this->serverParams->getPostMaxSize();
         if (!empty($maxContentLength) && $contentLength > $maxContentLength) {
             // Submit the form, but don't clear the default values
             $form->submit(null, false);
             $form->addError(new FormError($form->getConfig()->getOption('post_max_size_message'), null, array('{{ max }}' => $this->serverParams->getNormalizedIniPostMaxSize())));
             return;
         }
         if ('' === $name) {
             $params = $request->request->all();
             $files = $request->files->all();
         } elseif ($request->request->has($name) || $request->files->has($name)) {
             $default = $form->getConfig()->getCompound() ? array() : null;
             $params = $request->request->get($name, $default);
             $files = $request->files->get($name, $default);
         } else {
             // Don't submit the form if it is not present in the request
             return;
         }
         if (is_array($params) && is_array($files)) {
             $data = array_replace_recursive($params, $files);
         } else {
             $data = $params ?: $files;
         }
     }
     // Don't auto-submit the form unless at least one field is present.
     if ('' === $name && count(array_intersect_key($data, $form->all())) <= 0) {
         return;
     }
     $form->submit($data, 'PATCH' !== $method);
 }
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:61,代码来源:HttpFoundationRequestHandler.php

示例12: addError

 /**
  * {@inheritdoc}
  */
 public function addError(FormError $error)
 {
     if ($this->parent && $this->config->getErrorBubbling()) {
         $this->parent->addError($error);
     } else {
         $this->errors[] = $error;
     }
     return $this;
 }
开发者ID:senthil-r-wiredelta,项目名称:meilleure-visite,代码行数:12,代码来源:Form.php

示例13: errorResponse

 /**
  * @param $form
  * @param $message
  * @return JsonResponse
  */
 private function errorResponse(Request $request, FormInterface $form, $message)
 {
     $form->addError(new FormError($message));
     if ($request->isXmlHttpRequest()) {
         return new JsonResponse(['message' => $message, 'form' => $this->renderView('VivaitTaskstackCommunicatorBundle:HelpPanel:form.html.twig', ['form' => $form->createView()])], 400);
     } else {
         return $this->pageResponse($form);
     }
 }
开发者ID:vivait,项目名称:taskstack-communicator-bundle,代码行数:14,代码来源:HelpPanelController.php

示例14: updateUserAndForm

 private function updateUserAndForm(User &$user, FormInterface &$form, UserService $userService)
 {
     $cyrillicName = $userService->transliterate($user->getLiteralUsername());
     if ($this->isAllreadyExists($cyrillicName)) {
         $errorMessage = $this->get('translator')->trans('fos_user.username.already_used', [], 'validators');
         $form->addError(new FormError($errorMessage));
     } else {
         $user->setName($cyrillicName);
     }
 }
开发者ID:Nosolok,项目名称:Kingdom,代码行数:10,代码来源:RegistrationController.php

示例15: process

 /**
  * Process form
  *
  * @param  User $entity
  *
  * @return bool  True on successful processing, false otherwise
  */
 public function process(User $entity)
 {
     if (in_array($this->request->getMethod(), ['POST', 'PUT'])) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             $entity->setPlainPassword($this->form->get('password')->getData());
             $entity->setPasswordChangedAt(new \DateTime());
             try {
                 $this->mailerProcessor->sendChangePasswordEmail($entity);
             } catch (\Exception $e) {
                 $this->form->addError(new FormError($this->translator->trans('oro.email.handler.unable_to_send_email')));
                 $this->logger->error('Email sending failed.', ['exception' => $e]);
                 return false;
             }
             $this->userManager->updateUser($entity);
             return true;
         }
     }
     return false;
 }
开发者ID:Maksold,项目名称:platform,代码行数:27,代码来源:SetPasswordHandler.php


注:本文中的Symfony\Component\Form\FormInterface::addError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。