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


PHP Form::getErrors方法代码示例

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


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

示例1: convertFormToArray

 private function convertFormToArray(GenericSerializationVisitor $visitor, Form $data)
 {
     $isRoot = null === $visitor->getRoot();
     $form = new \ArrayObject();
     $errors = [];
     foreach ($data->getErrors() as $error) {
         $errors[] = $this->getErrorMessage($error);
     }
     if (!empty($errors)) {
         $form['errors'] = $errors;
     }
     $children = [];
     foreach ($data->all() as $child) {
         if ($child instanceof Form) {
             $children[$child->getName()] = $this->convertFormToArray($visitor, $child);
         }
     }
     if (!empty($children)) {
         $form['children'] = $children;
     }
     if ($isRoot) {
         $visitor->setRoot($form);
     }
     return $form;
 }
开发者ID:koesie10,项目名称:LuaSerializer,代码行数:25,代码来源:LuaFormHandler.php

示例2: getErrorMessages

 protected function getErrorMessages(\Symfony\Component\Form\Form $form, $name)
 {
     $errors = array();
     foreach ($form->getErrors() as $key => $error) {
         $errors[] = $error->getMessage();
     }
     foreach ($form->all() as $child) {
         $type = $child->getConfig()->getType()->getName();
         if ($child->count() && $type !== 'choice') {
             $childErrors = $this->getErrorMessages($child, $child->getName());
             if (sizeof($childErrors)) {
                 $errors = array_merge($errors, $childErrors);
             }
         } else {
             if (!$child->isValid()) {
                 if ($name == "responsable1" || $name == "responsable2") {
                     $errors[$child->getParent()->getParent()->getName() . '_' . $name . '_' . $child->getName()] = $this->getErrorMessages($child, $child->getName());
                 } else {
                     $errors[$name . '_' . $child->getName()] = $this->getErrorMessages($child, $child->getName());
                 }
             }
         }
     }
     return $errors;
 }
开发者ID:JM-PFC,项目名称:CEIP-ST,代码行数:25,代码来源:FestivosController.php

示例3: stringifyFormErrors

 public function stringifyFormErrors(Form $form)
 {
     $errors = [];
     foreach ($form->getErrors(true, true) as $error) {
         $errors[] = $error->getMessage();
     }
     return implode('<br>', $errors);
 }
开发者ID:Kid-Binary,项目名称:FRB,代码行数:8,代码来源:FormErrorHandlerTrait.php

示例4: createView

 public function createView(Form $form, $template, $parameters, $extraParameters = [])
 {
     $html = $this->templating->render($template, $parameters);
     $response = new JsonResponse();
     $response->setData(array_merge($extraParameters, ['submitted' => $form->isSubmitted(), 'errors' => count($form->getErrors(true)), 'html' => $html]));
     return $response;
 }
开发者ID:alpixel,项目名称:AlpixelFormBundle,代码行数:7,代码来源:ModalFormBuilder.php

示例5: getFormErrorMessages

 /**
  * Gets a form error messages
  *
  * @param Form $form
  *
  * @return array|string
  */
 public static function getFormErrorMessages(Form $form)
 {
     $errors = [];
     foreach ($form->getErrors(true, true) as $error) {
         $errors = $error->getMessage();
     }
     return $errors;
 }
开发者ID:sbernal93,项目名称:books,代码行数:15,代码来源:MessageBuilder.php

示例6: getErrorMessages

 private function getErrorMessages(Form $form)
 {
     $errors = [];
     foreach ($form->getErrors(true, true) as $key => $error) {
         $errors[] = $error->getMessage();
     }
     return $errors;
 }
开发者ID:keganv,项目名称:rock-paper-scissors-spock-lizard-game,代码行数:8,代码来源:UserController.php

示例7: stringifyFormErrors

 public function stringifyFormErrors(Form $form)
 {
     $errors = [];
     foreach ($form->getErrors(TRUE, TRUE) as $error) {
         $errors[] = $error->getMessage();
     }
     //return implode(', ', $errors);
     return !empty($errors[0]) ? $errors[0] : NULL;
 }
开发者ID:Kid-Binary,项目名称:KamillNurakhmetov,代码行数:9,代码来源:FormErrorHandlerTrait.php

示例8: addFormErrors

 /**
  * Method to add form errors to the response array
  *
  * @param Form $form            
  * @return \AppBundle\Controller\AppController
  */
 protected function addFormErrors(Form $form)
 {
     $response = array();
     $response['errorCode'] = self::FORM_ERRORS;
     foreach ($form->getErrors(true) as $error) {
         $response['errorMessage'][] = $error->getMessage();
     }
     $this->response = $response;
     return $this;
 }
开发者ID:aspire-lamp-hackathon,项目名称:services,代码行数:16,代码来源:AppController.php

示例9: tryFormValidate

 /**
  * フォームのバリデーションを行う
  * ※ServiceクラスでEntityのバリデーションを行っているが、
  * FormTypeクラスで設定したチェックや、CSRFトークンのチェックは
  * $form->isValid()でないと検証できないため、
  * フォームの検証の場合、本メソッドを使用すること
  *
  * @param Form $form
  * @throws FormValidationException
  */
 private function tryFormValidate(Form $form)
 {
     if (!$form->isValid()) {
         $exception = new FormValidationException();
         foreach ($form->getErrors(true, true) as $error) {
             $exception->addErrorMessage($error->getMessage());
         }
         throw $exception;
     }
 }
开发者ID:pinekta,项目名称:MyTestSample,代码行数:20,代码来源:CreateFormHelperTrait.php

示例10: saveErrorsToFlashBag

 /**
  * @param Request $request
  * @param
  *            $form
  * @param
  *            $errors
  */
 protected function saveErrorsToFlashBag(Request $request, Form $form)
 {
     $formClass = get_class($form->getConfig()->getType()->getInnerType());
     $errors = [];
     foreach ($form->getErrors(TRUE) as $error) {
         $cause = $error->getCause();
         $errors[] = ['message' => $error->getMessage(), 'messageTemplate' => $error->getMessageTemplate(), 'messageParameters' => $error->getMessageParameters(), 'messagePluralization' => $error->getMessagePluralization(), 'cause' => preg_replace('/data\\.|children\\[(.*?)\\]/', '$1', $cause->getPropertyPath()), 'invalidValue' => $cause->getInvalidValue()];
     }
     $this->addFlash('validation_error_' . $formClass, $errors);
     $this->addFlash('validation_error_request_' . $formClass, $request);
 }
开发者ID:lobiferi,项目名称:TTWorkshop,代码行数:18,代码来源:TTControllerHelperTrait.php

示例11: getFormErrorsArray

 public function getFormErrorsArray(Form $form, $prefix = '')
 {
     $errors = array();
     $errors['count'] = count($form->getErrors());
     $errors['count_deep'] = count($form->getErrors(true));
     if (count($form->getErrors()) > 0) {
         $errors['global'] = array();
     }
     /**
      * @var FormError $globalError
      */
     foreach ($form->getErrors() as $globalError) {
         $errors['global'][] = $this->translator->trans($globalError->getMessage());
     }
     /**
      * @var FormInterface $child
      */
     foreach ($form->all() as $name => $child) {
         if (count($child->getErrors()) > 0) {
             $errors[sprintf('%s%s', $prefix, $name)] = array();
         }
         /**
          * @var FormError $error
          */
         foreach ($child->getErrors() as $error) {
             $errors[sprintf('%s%s', $prefix, $name)][] = $this->translator->trans($error->getMessage());
         }
         if (count($child->all()) > 0) {
             foreach ($child->all() as $nameChild => $childChild) {
                 $name = sprintf('%s_%s', $name, $nameChild);
                 if (count($childChild->getErrors()) > 0) {
                     $errors[sprintf('%s%s', $prefix, $name)] = array();
                 }
                 foreach ($childChild->getErrors() as $error) {
                     $errors[sprintf('%s%s', $prefix, $name)][] = $this->translator->trans($error->getMessage());
                 }
             }
         }
     }
     return $errors;
 }
开发者ID:jahller,项目名称:streetartlas,代码行数:41,代码来源:ErrorPreparer.php

示例12: getErrors

 /**
  * @return array
  */
 protected function getErrors()
 {
     $errors = [];
     $generalErrors = [];
     foreach ($this->form->getErrors() as $error) {
         $generalErrors[] = $error->getMessage();
     }
     if (!empty($generalErrors)) {
         $errors['general'] = $generalErrors;
     }
     foreach ($this->form->all() as $field) {
         $fieldErrors = [];
         foreach ($field->getErrors() as $error) {
             $fieldErrors[] = $error->getMessage();
         }
         if (!empty($fieldErrors)) {
             $errors[$field->getName()] = $fieldErrors;
         }
     }
     return $errors;
 }
开发者ID:dominikmatt,项目名称:sulu-form-bundle,代码行数:24,代码来源:FormController.php

示例13: getErrorsArray

 /**
  * @param Form $form The form
  * @param string $namePrefix The field name prefix (concatenation of parents names).
  * @return array The form errors, as an array
  */
 private function getErrorsArray(Form $form, $namePrefix = '')
 {
     $formName = $namePrefix ? sprintf('%s[%s]', $namePrefix, $form->getName()) : $form->getName();
     $errors = array();
     foreach ($form->getErrors() as $error) {
         if (!isset($errors[$formName])) {
             $errors[$formName] = array();
         }
         $errors[$formName][] = $error->getMessage();
     }
     return $errors;
 }
开发者ID:blab2015,项目名称:seh,代码行数:17,代码来源:AbstractFormErrorsHelper.php

示例14: getErrorMessages

 /**
  * @param Form $form
  *
  * @return array
  */
 public function getErrorMessages(Form $form)
 {
     $errors = array();
     foreach ($form->getErrors() as $key => $error) {
         $errors[] = $error->getMessage();
     }
     foreach ($form->all() as $child) {
         if (!$child->isValid()) {
             $errors[$child->getName()] = $this->getErrorMessages($child);
         }
     }
     return $errors;
 }
开发者ID:SalmaAbdelhady,项目名称:Blog,代码行数:18,代码来源:APIHelper.php

示例15: serializeFormErrors

 public function serializeFormErrors(\Symfony\Component\Form\Form $form, $flat_array = false, $add_form_name = false, $glue_keys = '_')
 {
     $errors = array();
     $errors['global'] = array();
     $errors['fields'] = array();
     foreach ($form->getErrors() as $error) {
         $errors['global'][] = $error->getMessage();
     }
     $errors['fields'] = $this->serialize($form);
     if ($flat_array) {
         $errors['fields'] = $this->arrayFlatten($errors['fields'], $glue_keys, $add_form_name ? $form->getName() : '');
     }
     return $errors;
 }
开发者ID:Pulpmedia,项目名称:PulpmediaNgHttpBundle,代码行数:14,代码来源:FormErrorsSerializer.php


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