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


PHP Form::getMessages方法代码示例

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


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

示例1: hasFormErrors

 protected function hasFormErrors(Form $form)
 {
     foreach ($form->getMessages() as $message) {
         if (count($message) > 0) {
             return true;
         }
     }
     return false;
 }
开发者ID:kristjanAnd,项目名称:SimpleIV,代码行数:9,代码来源:Messages.php

示例2: testSettingValidateAllFlagAfterPartialValidationForcesFullValidation

 public function testSettingValidateAllFlagAfterPartialValidationForcesFullValidation()
 {
     $this->populateForm();
     $this->form->setValidationGroup('foo');
     $validSet = array('foo' => 'abcde');
     $this->form->setData($validSet);
     $this->form->setValidationGroup(Form::VALIDATE_ALL);
     $this->assertFalse($this->form->isValid());
     $messages = $this->form->getMessages();
     $this->assertArrayHasKey('foobar', $messages, var_export($messages, 1));
 }
开发者ID:razvansividra,项目名称:pnlzf2-1,代码行数:11,代码来源:FormTest.php

示例3: formErros

 /**
  * Pega as mensagens do formulario e as dispoe
  * em forma de lista ul,li
  * @param \Zend\Form\Form $form
  * @return string HTML
  */
 public function formErros($form)
 {
     $msg = "";
     $arrayMessage = $form->getMessages();
     foreach ($arrayMessage as $elemName => $messages) {
         foreach ($messages as $message) {
             $label = "";
             $elemName = $form->get($elemName);
             if ($elemName != null) {
                 $label = $elemName->getLabel();
             }
             $msg .= "<ul><li>" . $label . " " . $message . "</li></ul>";
         }
     }
     return $msg;
 }
开发者ID:argentinaluiz,项目名称:js_zf2_library,代码行数:22,代码来源:Format.php

示例4: processForm

 /**
  * Process form
  * 
  * @return Response|null
  */
 public function processForm()
 {
     $request = $this->getRequest();
     $this->form->setData($request->getPost());
     $fm = $this->flashMessenger();
     if (!$this->form->isValid()) {
         $fm->addErrorMessage('The form was not valid. ' . var_export($this->form->getMessages(), true), 'error');
         return;
     }
     try {
         $object = $this->saveObject();
     } catch (\Exception $exception) {
     }
     if (isset($exception)) {
         $fm->addErrorMessage('The object was not saved. ' . $exception->getMessage());
         return;
     } else {
         $fm->addSuccessMessage('The object has been successfully saved!');
     }
     return $this->redirectTo($object);
 }
开发者ID:nicovogelaar,项目名称:crud-controller-module,代码行数:26,代码来源:AbstractCrudController.php

示例5: formAction

 public function formAction()
 {
     // Build a name element.
     $name = new Element('name');
     $name->setLabel('Your name');
     $name->setAttributes(array('type' => 'text'));
     // Build a submit button element.
     $send = new Element('send');
     $send->setLabel('Send');
     $send->setAttributes(array('type' => 'submit', 'value' => 'Send'));
     // Build a checkbox element.
     $check = new Checkbox('check');
     $check->setLabel('Checkbox example');
     // Build a multi-checkbox element.
     $multicheck = new MultiCheckbox('multicheck');
     $multicheck->setLabel('Multi checkbox example');
     $multicheck->setOptions(array('value_options' => array('One' => 'one', 'Two' => 'two')));
     // Assemble the form.
     $form = new Form('contact');
     $form->add($name);
     $form->add($check);
     $form->add($multicheck);
     $form->add($send);
     // Get the request if any.
     $request = $this->getRequest();
     $data = $request->getPost();
     $form->setData($data);
     // Validate the form
     if ($form->isValid()) {
         $validatedData = $form->getData();
         $success = 'Form submit was successful';
     } else {
         $success = 'Form submit failed';
         $messages = $form->getMessages();
     }
     // Set the method attribute for the form
     $form->setAttribute('method', 'post');
     return new ViewModel(array('form' => $form, 'success' => $success, 'messages' => $messages, 'data' => $data));
 }
开发者ID:Tony133,项目名称:zf-web,代码行数:39,代码来源:IndexController.php

示例6: saveAction

 public function saveAction(Params $params, Request $request, Response $response, Form $form, Finder $finderService, Update $updateService, Form $form, View $view)
 {
     if ($request->getMethod() !== Request::METHOD_PUT) {
         return $view;
     }
     $id = $params('id');
     $entity = $finderService->find(['T4webTranslate' => ['Words' => ['Id' => (int) $id]]]);
     if (!$entity) {
         $response->setStatusCode(Response::STATUS_CODE_404);
         $view->setErrors(['message' => 'bad params']);
         return $view;
     }
     $data = Json::decode($request->getContent(), Json::TYPE_ARRAY);
     $form->setData($data);
     if (!$form->isValid()) {
         $response->setStatusCode(Response::STATUS_CODE_404);
         $view->setErrors($form->getMessages());
         return $view;
     }
     $entity->populate($data);
     $result = $updateService->update($id, $entity->extract());
     $view->setVariables($result->extract());
     return $view;
 }
开发者ID:sebaks,项目名称:Translate,代码行数:24,代码来源:AjaxWordController.php

示例7: hasMessage

 /**
  * Retorna classe (css) para elementos que tem mensagem (erro)
  * 
  * @param string $element
  * @param string $ifYes
  * @return string
  */
 public function hasMessage($element, $ifYes = 'alert-danger')
 {
     return (bool) parent::getMessages($element) ? $ifYes : '';
 }
开发者ID:braghimsistemas,项目名称:zf2lib,代码行数:11,代码来源:AbstractForm.php

示例8: testOnlyElementsWithErrorsInMessages

 public function testOnlyElementsWithErrorsInMessages()
 {
     $fieldset = new TestAsset\FieldsetWithInputFilter('set');
     $fieldset->add(new Element('foo'));
     $fieldset->add(new Element('bar'));
     $form = new Form();
     $form->add($fieldset);
     $form->setInputFilter(new InputFilter());
     $form->setData(array());
     $form->isValid();
     $messages = $form->getMessages();
     $this->assertArrayHasKey('foo', $messages['set']);
     $this->assertArrayNotHasKey('bar', $messages['set']);
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:14,代码来源:FieldsetTest.php

示例9: testElementsOfSubFormReceiveCorrectDefaultTranslator

 /**
  * @group ZF-11831
  */
 public function testElementsOfSubFormReceiveCorrectDefaultTranslator()
 {
     $isEmptyKey = \Zend\Validator\NotEmpty::IS_EMPTY;
     // Global default translator
     $trDefault = new Translator(array('adapter' => 'arrayAdapter', 'content' => array($isEmptyKey => 'Default'), 'locale' => 'en'));
     Registry::set('Zend_Translate', $trDefault);
     // Translator to use for elements
     $trElement = new Translator(array('adapter' => 'arrayAdapter', 'content' => array($isEmptyKey => 'Element'), 'locale' => 'en'));
     \Zend\Validator\AbstractValidator::setDefaultTranslator($trElement);
     // Change the form's translator
     $form = new Form();
     $form->addElement(new \Zend\Form\Element\Text('foo', array('required' => true, 'validators' => array('NotEmpty'))));
     // Create a subform with it's own validator
     $sf1 = new SubForm();
     $sf1->addElement(new \Zend\Form\Element\Text('foosub', array('required' => true, 'validators' => array('NotEmpty'))));
     $form->addSubForm($sf1, 'Test1');
     $form->isValid(array());
     $messages = $form->getMessages();
     $this->assertEquals('Element', @$messages['foo'][$isEmptyKey], 'Form element received wrong validator');
     $this->assertEquals('Element', @$messages['Test1']['foosub'][$isEmptyKey], 'SubForm element received wrong validator');
 }
开发者ID:rafalwrzeszcz,项目名称:zf2,代码行数:24,代码来源:FormTest.php

示例10: testCanGetMessagesOfNestedFormsWithMultiLevelElementsBelongingToArrays

 public function testCanGetMessagesOfNestedFormsWithMultiLevelElementsBelongingToArrays()
 {
     $form = new Form();
     $form->setElementsBelongTo('foo[bar]');
     $form->addElement('text', 'firstName')->getElement('firstName')->setRequired(false);
     $form->addElement('text', 'lastName')->getElement('lastName')->setRequired(true);
     $subForm = new \Zend\Form\SubForm();
     $subForm->setElementsBelongTo('baz');
     $subForm->addElement('text', 'email')->getElement('email')->setRequired(true)->addValidator('NotEmpty');
     $subSubForm = new \Zend\Form\SubForm();
     $subSubForm->setElementsBelongTo('bat[quux]');
     $subSubForm->addElement('checkbox', 'home')->getElement('home')->setRequired(true)->addValidator('InArray', false, array(array('1')));
     $subForm->addSubForm($subSubForm, 'subSub');
     $form->addSubForm($subForm, 'sub')->addElement('submit', 'save', array('value' => 'submit'));
     $data = array('foo' => array('bar' => array('lastName' => 'Cow')));
     $form->sub->subSub->home->addValidator('StringLength', false, array(4, 6));
     $data['foo']['bar']['baz'] = array('bat' => array('quux' => array('home' => 'ab')));
     $form->isValidPartial($data);
     $messages = $form->getMessages();
     $this->assertFalse(empty($messages));
     $this->assertTrue(isset($messages['foo']['bar']['baz']['bat']['quux']['home']), var_export($messages, 1));
     $this->assertTrue(isset($messages['foo']['bar']['baz']['bat']['quux']['home']['notInArray']), var_export($messages, 1));
 }
开发者ID:rexmac,项目名称:zf2,代码行数:23,代码来源:FormTest.php

示例11: hydrate

 /**
  * Hydrate an array of data onto an entity using a form
  *
  * @param AbstractEntity $entity
  * @param array $values
  * @param Form $form
  * @return AbstractEntity
  */
 private function hydrate(AbstractEntity $entity, array $values, Form $form)
 {
     $form->setObject($entity);
     if ($form->getBaseFieldset()) {
         $form->getBaseFieldset()->setObject($entity);
     }
     $form->setData($values);
     if (!$form->isValid()) {
         return $this->setErrorMessages($form->getMessages());
     }
     $result = $form->getData();
     if (!$result instanceof AbstractEntity) {
         throw new RuntimeException('Unable to retrieve entity from Form');
     }
     return $result;
 }
开发者ID:outeredge,项目名称:edge-zf2,代码行数:24,代码来源:AbstractRepositoryService.php

示例12: handleErrors

 /**
  * Check if the form is valid and return a response object if invalid
  * @param \Zend\Form\Form $form
  * @return bool|\Zend\Stdlib\ResponseInterface
  */
 private function handleErrors(\Zend\Form\Form $form)
 {
     $request = $this->getRequest();
     $form->setData($request->getPost()->toArray());
     if (!$form->isValid()) {
         return $this->jsonResponse(array('success' => false, 'errors' => $form->getMessages()));
     }
     return false;
 }
开发者ID:Ellipizle,项目名称:dotscms,代码行数:14,代码来源:AdminController.php

示例13: parseFormMessage

 /**
  * @param \Zend\Form\Form $form
  * @return bool|string
  */
 private function parseFormMessage($form)
 {
     if (is_array($form->getMessages())) {
         $errorMessage = '';
         foreach ($form->getMessages() as $title => $values) {
             $formElement = $form->getElements();
             $errorMessage .= $formElement[$title]->getLabel() . PHP_EOL;
             if (is_array($values)) {
                 foreach ($values as $value) {
                     $errorMessage .= '<li>' . $value . '</li>';
                 }
             } else {
                 $errorMessage .= $values;
             }
         }
         return $errorMessage;
     } elseif (is_string($form->getMessages())) {
         return $form->getMessages();
     } else {
         return false;
     }
 }
开发者ID:arbi,项目名称:MyCode,代码行数:26,代码来源:General.php

示例14: testValidateData

 public function testValidateData()
 {
     $myFieldset = new Fieldset();
     $myFieldset->add(array('name' => 'email', 'type' => 'Email'));
     $myForm = new Form();
     $myForm->add(array('name' => 'collection', 'type' => 'Collection', 'options' => array('target_element' => $myFieldset)));
     $data = array('collection' => array(array('email' => 'test1@test1.com'), array('email' => 'test2@test2.com'), array('email' => 'test3@test3.com')));
     $myForm->setData($data);
     $this->assertTrue($myForm->isValid());
     $this->assertEmpty($myForm->getMessages());
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:11,代码来源:CollectionTest.php

示例15: updateIteration

 /**
  * @param $tag
  * @param  Form   $form
  * @param  Params $params
  * @return bool
  */
 public function updateIteration($tag, Form $form, Params $params)
 {
     $valid = true;
     $this->getEventManager()->trigger(self::EVENT_FORM_DATA . $tag, $this, array('form' => $form, 'data' => $params));
     if (!$this->call($this->getFormValidators(), $tag, array($params, $form), function (Params $params, Form $form) {
         return $form->isValid();
     })) {
         $valid = false;
         $this->errorMessages[$tag] = $this->normalizeMessages($form->getMessages());
     }
     return $valid;
 }
开发者ID:fousheezy,项目名称:common,代码行数:18,代码来源:Base.php


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