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


PHP Form::addError方法代码示例

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


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

示例1: handleFlashErrors

 public static function handleFlashErrors(SymfonyForm $form, $identifier)
 {
     $errors = self::$app['flashbag']->get('form.' . $identifier . '.errors');
     foreach ($errors as $error) {
         $form->addError(new FormError($error));
     }
 }
开发者ID:pinodex,项目名称:boardy,代码行数:7,代码来源:Form.php

示例2: setErrorsInForm

 /** -------------------------
  * Error handler for (repeated) driving orders
  *
  * Displays all errors on the top of the form as a list.
  *
  * @param array $errors
  * @param Form $form
  * @return mixed
  */
 protected function setErrorsInForm($errors, Form &$form)
 {
     $tr = $this->container->get('translator');
     foreach ($errors as $error) {
         $form->addError(new FormError($tr->trans($error)));
     }
     return count($errors);
 }
开发者ID:binaryfr3ak,项目名称:sfitixi,代码行数:17,代码来源:DrivingOrderController.php

示例3: editEventUsingForm

 /**
  * Submits the form data to the API and returns the edited event, false if there is an error or null
  * if it is held for moderation.
  *
  * Should an error occur will this method append an error message to the form's error collection.
  *
  * @param Form $form
  *
  * @return EventEntity|null|false
  */
 private function editEventUsingForm(Form $form)
 {
     $eventApi = $this->getEventApi();
     $values = $form->getData()->toArray();
     $result = false;
     try {
         $result = $eventApi->edit($values);
     } catch (\Exception $e) {
         $form->addError(new FormError('An error occurred while editing your event: ' . $e->getMessage()));
     }
     try {
         if (isset($_FILES['event']['error']['new_icon']) && $_FILES['event']['error']['new_icon'] == UPLOAD_ERR_OK) {
             $eventApi->uploadIcon($result->getImagesUri(), $_FILES['event']['tmp_name']['new_icon']);
         }
     } catch (\Exception $e) {
         $result = false;
         $error = $e->getMessage();
         $messages = json_decode($error);
         if ($messages) {
             $error = implode(', ', $messages);
         }
         $form->addError(new FormError("An error occurred while uploading your event icon: {$error}"));
     }
     return $result;
 }
开发者ID:AurelioDeRosa,项目名称:joindin-web2,代码行数:35,代码来源:EventController.php

示例4: isValid

 public function isValid(\Symfony\Component\Form\Form &$form)
 {
     $viewData = $form->getViewData();
     //pour le champ hidden allFieldsAreThere de Revision
     if (!is_object($viewData) && 'allFieldsAreThere' == $form->getName()) {
         return true;
     }
     if ($viewData instanceof Revision) {
         /** @var DataField $dataField */
         $dataField = $viewData->getDatafield();
     } elseif ($viewData instanceof DataField) {
         /** @var DataField $dataField */
         $dataField = $viewData;
     } else {
         throw new \Exception("Unforeseen type of viewData");
     }
     if ($dataField->getFieldType() !== null && $dataField->getFieldType()->getType() !== null) {
         $dataFieldTypeClassName = $dataField->getFieldType()->getType();
         /** @var DataFieldType $dataFieldType */
         $dataFieldType = new $dataFieldTypeClassName();
     }
     $isValid = true;
     if (isset($dataFieldType) && $dataFieldType->isContainer()) {
         //If datafield is container or type is null => Container => Recursive
         $formChildren = $form->all();
         foreach ($formChildren as $child) {
             if ($child instanceof \Symfony\Component\Form\Form) {
                 $tempIsValid = $this->isValid($child);
                 //Recursive
                 $isValid = $isValid && $tempIsValid;
             }
         }
         if (!$isValid) {
             $form->addError(new FormError("At least one child is not valid!"));
         }
     }
     //   		$isValid = $isValid && $dataFieldType->isValid($dataField);
     if (isset($dataFieldType) && !$dataFieldType->isValid($dataField)) {
         $isValid = false;
         $form->addError(new FormError("This Field is not valid! " . $dataField->getMessages()[0]));
     }
     return $isValid;
 }
开发者ID:theus77,项目名称:ElasticMS,代码行数:43,代码来源:DataService.php

示例5: setFormErrors

 /**
  * @param Form   $form
  * @param object $contract
  * @return Form
  */
 public function setFormErrors($form, $contract)
 {
     if (isset($contract->errors->children) && ($errors = $contract->errors->children)) {
         foreach ($errors as $key => $error) {
             if (is_object($error) && isset($error->errors[0])) {
                 $form->addError(new FormError(isset($this->getErrorsMessage()[$key]) ? $this->getErrorsMessage()[$key] : 'Something is wrong'));
             }
         }
     } else {
         $form->addError(new FormError('Something is wrong'));
     }
     return $form;
 }
开发者ID:plescanicolai,项目名称:billingSdk,代码行数:18,代码来源:Auth.php

示例6: onUpdate

 public function onUpdate(Controller $controller, Request $request, ActionCache $action, $object, Form $form)
 {
     if ($object->default_group || $object->trust_group) {
         $roles = $this->admin_loader->getRoleHierarchy();
         foreach ($object->getRoles() as $role) {
             if ('ROLE_ADMIN' === $role || isset($roles[$role]) && in_array('ROLE_ADMIN', $roles[$role])) {
                 $form->addError(new \Symfony\Component\Form\FormError($this->trans(".form.default_group.no_admin")));
                 return;
             }
         }
         if ($object->hasRole('ROLE_ADMIN')) {
         }
         if ($object->default_group && $object->trust_group) {
             $form->addError(new \Symfony\Component\Form\FormError($this->trans(".form.default_group.trust_default_conflict")));
             return;
         }
         $em = $this->getManager();
         $repo = $this->getRepository();
         $groups = $repo->findAll();
         foreach ($groups as $group) {
             if ($group->isEqual($object)) {
                 continue;
             }
             if ($object->default_group) {
                 if ($group->default_group) {
                     $group->default_group = false;
                     $em->persist($group);
                 }
             }
             if ($object->trust_group) {
                 if ($group->trust_group) {
                     $group->trust_group = false;
                     $em->persist($group);
                 }
             }
         }
     }
     parent::onUpdate($controller, $request, $action, $object, $form);
 }
开发者ID:symforce,项目名称:symforce-user,代码行数:39,代码来源:GroupAdmin.php

示例7: registerUser_

 /**
  * @param \Symfony\Component\Form\Form $form
  */
 public function registerUser_(\Symfony\Component\Form\Form $form)
 {
     /* @var Championship\EventBundle\Classes\Form\User\Register $userRegister */
     $userRegister = $form->getData();
     // save data
     $userLogin = new UserLogin();
     $userLogin->setLogin($userRegister->login);
     $userLogin->setAuthData($userRegister->password);
     $user = new User();
     $user->setNick($userRegister->nick);
     // user -> user_login
     $user->setUserLogin($userLogin);
     // user_login -> user
     $userLogin->setUser($user);
     // check unique
     if ($user->checkUnique($this->controller)) {
         $form->addError($this->addError('Not Unique Nick'));
         return false;
     }
     if ($userLogin->checkUnique($this->controller)) {
         $form->addError($this->addError('Not Unique login'));
         return false;
     }
     $event = NotificationClient::createEvent($userLogin->getLogin(), $userLogin->generateMessage(), 1);
     if (false === $event) {
         $form->addError($this->addError('Event not create'));
         return false;
     }
     $doctrine = $this->controller->getDoctrine()->getEntityManager();
     $doctrine->persist($event);
     $doctrine->persist($userLogin);
     $doctrine->persist($user);
     $doctrine->flush();
     //
     return true;
 }
开发者ID:raketman,项目名称:MakeSymfony,代码行数:39,代码来源:ActionModel.php

示例8: addStorageExceededFormError

 /**
  * Adds the storage exceeded error in a form.
  *
  * @param Form $form
  * @param integer $filesize
  */
 public function addStorageExceededFormError(Form $form, $fileSize, Workspace $workspace)
 {
     $filesize = $this->ut->getRealFileSize($fileSize);
     //we want how many bites and well...
     $maxSize = $this->ut->getRealFileSize($workspace->getMaxStorageSize());
     //throw new \Exception($maxSize);
     $usedSize = $this->ut->getRealFileSize($this->container->get('claroline.manager.workspace_manager')->getUsedStorage($workspace));
     $storageLeft = $maxSize - $usedSize;
     $fileSize = $this->ut->formatFileSize($fileSize);
     $storageLeft = $this->ut->formatFileSize($storageLeft);
     $translator = $this->container->get('translator');
     $msg = $translator->trans('storage_limit_exceeded', array('%storageLeft%' => $storageLeft, '%fileSize%' => $fileSize), 'platform');
     $form->addError(new FormError($msg));
 }
开发者ID:ChMat,项目名称:CoreBundle,代码行数:20,代码来源:ResourceManager.php

示例9: editEventUsingForm

 /**
  * Submits the form data to the API and returns the edited event, false if there is an error or null
  * if it is held for moderation.
  *
  * Should an error occur will this method append an error message to the form's error collection.
  *
  * @param Form $form
  *
  * @return EventEntity|null|false
  */
 private function editEventUsingForm(Form $form)
 {
     $eventApi = $this->getEventApi();
     $values = $form->getData()->toArray();
     $result = false;
     try {
         $result = $eventApi->edit($values);
     } catch (\Exception $e) {
         $form->addError(new FormError('An error occurred while editing your event: ' . $e->getMessage()));
     }
     return $result;
 }
开发者ID:xsist10,项目名称:joindin-web2,代码行数:22,代码来源:EventController.php

示例10: addStorageExceededFormError

 /**
  * Adds the storage exceeded error in a form.
  *
  * @param Form $form
  * @param int  $filesize
  */
 public function addStorageExceededFormError(Form $form, $fileSize, Workspace $workspace)
 {
     $maxSize = $this->ut->getRealFileSize($workspace->getMaxStorageSize());
     $usedSize = $this->ut->getRealFileSize($this->container->get('claroline.manager.workspace_manager')->getUsedStorage($workspace));
     $storageLeft = $maxSize - $usedSize;
     $fileSize = $this->ut->formatFileSize($this->ut->getRealFileSize($fileSize));
     $storageLeft = $this->ut->formatFileSize($storageLeft);
     $translator = $this->container->get('translator');
     $msg = $translator->trans('storage_limit_exceeded', ['%storageLeft%' => $storageLeft, '%fileSize%' => $fileSize], 'platform');
     $form->addError(new FormError($msg));
 }
开发者ID:claroline,项目名称:distribution,代码行数:17,代码来源:ResourceManager.php

示例11: checkForm4

 public function checkForm4(Form $form, ValidatorInterface $validator, TranslatorInterface $translator)
 {
     if ($form->isValid()) {
         $this->a_total = $this->a_teramo_wb + $this->a_teramo_wob + $this->a_teramo_tent + $this->a_guilianova_tent + $this->a_restaurant + $this->a_teramo_hotel + $this->a_guilianova_hotel + $this->a_none;
         if ($this->a_total == null || trim($this->a_total) == '') {
             $form->addError(new FormError($translator->trans('FORM.ENROLLMENT.NOACCOMODATION', array(), 'club')));
         }
     }
     return $form->isValid();
 }
开发者ID:armandomeeuwenoord,项目名称:icup,代码行数:10,代码来源:Enrollment.php

示例12: testNestedFormErrors

 public function testNestedFormErrors()
 {
     $dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $formConfig = $this->getMock('Symfony\\Component\\Form\\FormConfigInterface');
     $formConfig->expects($this->any())->method('getEventDispatcher')->will($this->returnValue($dispatcher));
     $formConfig->expects($this->any())->method('getModelTransformers')->will($this->returnValue(array()));
     $fooConfig = clone $formConfig;
     $fooConfig->expects($this->any())->method('getName')->will($this->returnValue('foo'));
     $form = new Form($fooConfig);
     $form->addError(new FormError('This is the form error'));
     $barConfig = clone $formConfig;
     $barConfig->expects($this->any())->method('getName')->will($this->returnValue('bar'));
     $child = new Form($barConfig);
     $child->addError(new FormError('Error of the child form'));
     $form->add($child);
     $this->assertEquals($this->getContent('nested_form_errors'), $this->serialize($form));
 }
开发者ID:hykz,项目名称:Depot,代码行数:17,代码来源:BaseSerializationTest.php

示例13: validateForm

 /**
  * @param Form $form
  */
 private function validateForm(Form $form)
 {
     foreach ($this->container->get('validator')->validate($form->getData()) as $error) {
         /* @var ConstraintViolation $error */
         $form->addError(new FormError(strtolower(preg_replace('/([A-Z])/', '_$1', $error->getPropertyPath()) . ': ' . $error->getMessage())));
     }
 }
开发者ID:staspiv,项目名称:rest-bundle,代码行数:10,代码来源:BaseController.php

示例14: hookValidationError

 /**
  * @param \Symfony\Component\Form\Form $form
  */
 protected function hookValidationError($form)
 {
     $form->addError(new FormError($this->__('Hook validation failed!')));
 }
开发者ID:shefik,项目名称:MediaModule,代码行数:7,代码来源:AbstractController.php

示例15: testAddErrorMapsErrorsOntoFieldsInVirtualGroups

 public function testAddErrorMapsErrorsOntoFieldsInVirtualGroups()
 {
     $error = new DataError('Message');
     // path is expected to point at "address"
     $expectedPath = new PropertyPath('address');
     $expectedPathIterator = $expectedPath->getIterator();
     $field = $this->createMockField('address');
     $field->expects($this->any())->method('getPropertyPath')->will($this->returnValue(new PropertyPath('address')));
     $field->expects($this->once())->method('addError')->with($this->equalTo($error), $this->equalTo($expectedPathIterator));
     $form = new Form('author');
     $nestedForm = new Form('nested', array('virtual' => true));
     $nestedForm->add($field);
     $form->add($nestedForm);
     $path = new PropertyPath('address');
     $form->addError($error, $path->getIterator());
 }
开发者ID:nickaggarwal,项目名称:sample-symfony2,代码行数:16,代码来源:FormTest.php


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