當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。