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


PHP FormInterface::getErrors方法代码示例

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


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

示例1: testSubmit

 /**
  * @dataProvider getValidInputs
  */
 public function testSubmit($submitted, $expected)
 {
     $this->sut->submit($submitted);
     $msg = '';
     if (!$this->sut->isValid()) {
         $msg = print_r($this->sut->getErrors(), true);
         foreach ($this->sut->all() as $child) {
             $msg .= "\n" . print_r($child->getErrors(), true);
         }
     }
     $this->assertTrue($this->sut->isValid(), $msg);
     $this->assertEquals($expected, $this->sut->getData());
 }
开发者ID:xtrasmal,项目名称:iinano,代码行数:16,代码来源:PublishingTestCase.php

示例2: getErrorMessages

 /**
  * Returns an array with form fields errors
  *
  * @param FormInterface $form
  * @param bool|false $useLabels
  * @param array $errors
  * @return array
  */
 public function getErrorMessages(FormInterface $form, $useLabels = false, $errors = array())
 {
     if ($form->count() > 0) {
         foreach ($form->all() as $child) {
             if (!$child->isValid()) {
                 $errors = $this->getErrorMessages($child, $useLabels, $errors);
             }
         }
     }
     foreach ($form->getErrors() as $error) {
         if ($useLabels) {
             $fieldNameData = $this->getErrorFormLabel($form);
         } else {
             $fieldNameData = $this->getErrorFormId($form);
         }
         $fieldName = $fieldNameData;
         if ($useLabels) {
             /**
              * @ignore
              */
             $fieldName = $this->translator->trans($fieldNameData['label'], array(), $fieldNameData['domain']);
         }
         $errors[$fieldName] = $error->getMessage();
     }
     return $errors;
 }
开发者ID:auamarto,项目名称:crud-bundle,代码行数:34,代码来源:FormErrorHandler.php

示例3: registerUser

 /**
  * @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;
 }
开发者ID:sunsingle,项目名称:gaestebuchtest,代码行数:30,代码来源:LoginManager.php

示例4: buildView

 public function buildView(FormView $view, FormInterface $form)
 {
     if ($view->hasParent()) {
         $parentId = $view->getParent()->get('id');
         $parentName = $view->getParent()->get('name');
         $id = sprintf('%s_%s', $parentId, $form->getName());
         $name = sprintf('%s[%s]', $parentName, $form->getName());
     } else {
         $id = $form->getName();
         $name = $form->getName();
     }
     $view->set('form', $view);
     $view->set('id', $id);
     $view->set('name', $name);
     $view->set('errors', $form->getErrors());
     $view->set('value', $form->getClientData());
     $view->set('read_only', $form->isReadOnly());
     $view->set('required', $form->isRequired());
     $view->set('max_length', $form->getAttribute('max_length'));
     $view->set('size', null);
     $view->set('label', $form->getAttribute('label'));
     $view->set('multipart', false);
     $view->set('attr', array());
     $types = array();
     foreach (array_reverse((array) $form->getTypes()) as $type) {
         $types[] = $type->getName();
     }
     $view->set('types', $types);
 }
开发者ID:norwayapp,项目名称:Invest,代码行数:29,代码来源:FieldType.php

示例5: buildView

 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form)
 {
     $name = $form->getName();
     if ($view->hasParent()) {
         if ('' === $name) {
             throw new FormException('Form node with empty name can be used only as root form node.');
         }
         if ('' !== ($parentFullName = $view->getParent()->get('full_name'))) {
             $id = sprintf('%s_%s', $view->getParent()->get('id'), $name);
             $fullName = sprintf('%s[%s]', $parentFullName, $name);
         } else {
             $id = $name;
             $fullName = $name;
         }
     } else {
         // If this form node have empty name, set id to `form`
         // to avoid rendering `id=""` in html structure
         $id = $name ?: 'form';
         $fullName = $name;
     }
     $types = array();
     foreach ($form->getTypes() as $type) {
         $types[] = $type->getName();
     }
     $view->set('form', $view)->set('id', $id)->set('name', $name)->set('full_name', $fullName)->set('errors', $form->getErrors())->set('value', $form->getClientData())->set('read_only', $form->isReadOnly())->set('required', $form->isRequired())->set('max_length', $form->getAttribute('max_length'))->set('pattern', $form->getAttribute('pattern'))->set('size', null)->set('label', $form->getAttribute('label'))->set('multipart', false)->set('attr', $form->getAttribute('attr'))->set('types', $types)->set('translation_domain', $form->getAttribute('translation_domain'));
 }
开发者ID:rudott,项目名称:symfony,代码行数:29,代码来源:FieldType.php

示例6: formatFormErrors

 /**
  * @param FormInterface     $form
  * @param array             $results
  *
  * @return array
  */
 private function formatFormErrors(FormInterface $form, &$results = array())
 {
     /*
      * first check if there are any errors bound for this element
      */
     $errors = $form->getErrors();
     if (count($errors)) {
         $messages = [];
         foreach ($errors as $error) {
             if ($error instanceof FormError) {
                 $messages[] = $this->translator->trans($error->getMessage(), $error->getMessageParameters(), 'validators');
             }
             $results[] = ['property_path' => $this->formatPropertyPath($error), 'message' => join(', ', $messages)];
         }
     }
     /*
      * Then, check if there are any children. If yes, then parse them
      */
     $children = $form->all();
     if (count($children)) {
         foreach ($children as $child) {
             if ($child instanceof FormInterface) {
                 $this->formatFormErrors($child, $results);
             }
         }
     }
     return $results;
 }
开发者ID:nass59,项目名称:Lab,代码行数:34,代码来源:PaginatedViewHandler.php

示例7: buildView

 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form)
 {
     $name = $form->getName();
     $readOnly = $form->getAttribute('read_only');
     if ($view->hasParent()) {
         if ('' === $name) {
             throw new FormException('Form node with empty name can be used only as root form node.');
         }
         if ('' !== ($parentFullName = $view->getParent()->get('full_name'))) {
             $id = sprintf('%s_%s', $view->getParent()->get('id'), $name);
             $fullName = sprintf('%s[%s]', $parentFullName, $name);
         } else {
             $id = $name;
             $fullName = $name;
         }
         // Complex fields are read-only if themselves or their parent is.
         $readOnly = $readOnly || $view->getParent()->get('read_only');
     } else {
         $id = $name;
         $fullName = $name;
         // Strip leading underscores and digits. These are allowed in
         // form names, but not in HTML4 ID attributes.
         // http://www.w3.org/TR/html401/struct/global.html#adef-id
         $id = ltrim($id, '_0123456789');
     }
     $types = array();
     foreach ($form->getTypes() as $type) {
         $types[] = $type->getName();
     }
     $view->set('form', $view)->set('id', $id)->set('name', $name)->set('full_name', $fullName)->set('read_only', $readOnly)->set('errors', $form->getErrors())->set('value', $form->getClientData())->set('disabled', $form->isDisabled())->set('required', $form->isRequired())->set('max_length', $form->getAttribute('max_length'))->set('pattern', $form->getAttribute('pattern'))->set('size', null)->set('label', $form->getAttribute('label'))->set('multipart', false)->set('attr', $form->getAttribute('attr'))->set('types', $types)->set('translation_domain', $form->getAttribute('translation_domain'));
 }
开发者ID:421p,项目名称:symfony,代码行数:34,代码来源:FormType.php

示例8: extractSubmittedData

 /**
  * {@inheritdoc}
  */
 public function extractSubmittedData(FormInterface $form)
 {
     $data = array('submitted_data' => array('norm' => $this->valueExporter->exportValue($form->getNormData())), 'errors' => array());
     if ($form->getViewData() !== $form->getNormData()) {
         $data['submitted_data']['view'] = $this->valueExporter->exportValue($form->getViewData());
     }
     if ($form->getData() !== $form->getNormData()) {
         $data['submitted_data']['model'] = $this->valueExporter->exportValue($form->getData());
     }
     foreach ($form->getErrors() as $error) {
         $errorData = array('message' => $error->getMessage(), 'origin' => is_object($error->getOrigin()) ? spl_object_hash($error->getOrigin()) : null, 'trace' => array());
         $cause = $error->getCause();
         while (null !== $cause) {
             if ($cause instanceof ConstraintViolationInterface) {
                 $errorData['trace'][] = array('class' => $this->valueExporter->exportValue(get_class($cause)), 'root' => $this->valueExporter->exportValue($cause->getRoot()), 'path' => $this->valueExporter->exportValue($cause->getPropertyPath()), 'value' => $this->valueExporter->exportValue($cause->getInvalidValue()));
                 $cause = method_exists($cause, 'getCause') ? $cause->getCause() : null;
                 continue;
             }
             if ($cause instanceof \Exception) {
                 $errorData['trace'][] = array('class' => $this->valueExporter->exportValue(get_class($cause)), 'message' => $this->valueExporter->exportValue($cause->getMessage()));
                 $cause = $cause->getPrevious();
                 continue;
             }
             $errorData['trace'][] = $cause;
             break;
         }
         $data['errors'][] = $errorData;
     }
     $data['synchronized'] = $this->valueExporter->exportValue($form->isSynchronized());
     return $data;
 }
开发者ID:xingshanghe,项目名称:symfony,代码行数:34,代码来源:FormDataExtractor.php

示例9: realParseErrors

 /**
  * This does the actual job. Method travels through all levels of form recursively and gathers errors.
  * @param FormInterface $form
  * @param array &$results
  *
  * @return FormError[]
  */
 private function realParseErrors(FormInterface $form, array &$results)
 {
     /*
      * first check if there are any errors bound for this element
      */
     $errors = $form->getErrors();
     if (count($errors)) {
         $config = $form->getConfig();
         $name = $form->getName();
         $label = $config->getOption('label');
         $translation = $this->getTranslationDomain($form);
         /*
          * If a label isn't explicitly set, use humanized field name
          */
         if (empty($label)) {
             $label = ucfirst(trim(strtolower(preg_replace(['/([A-Z])/', '/[_\\s]+/'], ['_$1', ' '], $name))));
         }
         $results[] = array('name' => $name, 'label' => $label, 'errors' => $errors);
     }
     /*
      * Then, check if there are any children. If yes, then parse them
      */
     $children = $form->all();
     if (count($children)) {
         foreach ($children as $child) {
             if ($child instanceof FormInterface) {
                 $this->realParseErrors($child, $results);
             }
         }
     }
     return $results;
 }
开发者ID:ex3v,项目名称:formerrorsbundle,代码行数:39,代码来源:FormErrorsParser.php

示例10: getErrors

 protected function getErrors(FormInterface $form)
 {
     $messages = [];
     foreach ($form->getErrors() as $message) {
         $messages[] = $message->getMessage();
     }
     return $messages;
 }
开发者ID:enhavo,项目名称:enhavo,代码行数:8,代码来源:CheckoutController.php

示例11: __construct

 public function __construct(FormInterface $form)
 {
     $message = [];
     foreach ($form->getErrors(true, true) as $error) {
         $message[] = sprintf('[%s] %s (%s)', $error->getOrigin() ? $error->getOrigin()->getPropertyPath() : '-', $error->getMessage(), json_encode($error->getMessageParameters()));
     }
     parent::__construct(implode("\n", $message));
 }
开发者ID:sulu,项目名称:sulu,代码行数:8,代码来源:InvalidFormException.php

示例12: getFormErrors

 /**
  * Gets an associative array with all the errors in a form and it's children.
  *
  * @param FormInterface $form
  *
  * @return array
  */
 public static function getFormErrors(FormInterface $form)
 {
     $errors = array();
     foreach ($form->getErrors() as $error) {
         $errors['_form_'][] = $error->getMessage();
     }
     self::addChildErrors($form, $errors);
     return $errors;
 }
开发者ID:proyecto404,项目名称:UtilBundle,代码行数:16,代码来源:FormUtil.php

示例13: __construct

 public function __construct(FormInterface $form)
 {
     $this->name = $form->getName();
     foreach ($form->getErrors() as $error) {
         $this->errors[] = $error;
     }
     foreach ($form->all() as $child) {
         $this->children[] = new static($child);
     }
 }
开发者ID:alekitto,项目名称:serializer,代码行数:10,代码来源:SerializableForm.php

示例14: getFormErrorMapping

 /**
  * Returns the form error mapping for easier marking of form errors in
  * javascript handler code.
  *
  * @param FormInterface $form
  *
  * @return array
  */
 protected function getFormErrorMapping(FormInterface $form)
 {
     $allErrors = array();
     $formName = $form->getName();
     $fieldPrefix = !empty($formName) ? "{$formName}_" : "";
     foreach ($form->all() as $children) {
         $errors = $children->getErrors();
         if (!empty($errors)) {
             $allErrors["{$fieldPrefix}{$children->getName()}"] = array_map(function (FormError $error) {
                 return $error->getMessage();
             }, is_array($errors) ? $errors : iterator_to_array($errors));
         }
     }
     if ($form->getErrors()->count() > 0) {
         foreach ($form->getErrors() as $topLevelError) {
             $allErrors["__global"][] = $topLevelError->getMessage();
         }
     }
     return $allErrors;
 }
开发者ID:Gemineye,项目名称:BecklynRadBundle,代码行数:28,代码来源:BaseController.php

示例15: buildView

 /**
  * @param FormView      $view
  * @param FormInterface $form
  * @param array         $options
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $errors = array();
     $fieldErrors = $form->getErrors();
     foreach ($fieldErrors as $fieldError) {
         $errors[] = $this->translator->trans($fieldError->getMessageTemplate(), $fieldError->getMessageParameters(), 'validators');
     }
     if ($errors) {
         $view->vars['attr']['data-error'] = implode("<br>", $errors);
     }
 }
开发者ID:simplethings,项目名称:js-validation-bundle,代码行数:16,代码来源:ErrorAttrTypeExtension.php


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