當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Form\Form類代碼示例

本文整理匯總了PHP中Zend\Form\Form的典型用法代碼示例。如果您正苦於以下問題:PHP Form類的具體用法?PHP Form怎麽用?PHP Form使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Form類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: loginAction

 /**
  * Login form
  */
 public function loginAction()
 {
     if ($this->zfcUserAuthentication()->hasIdentity()) {
         return $this->redirect()->toRoute($this->options->getLoginRedirectRoute());
     }
     $request = $this->getRequest();
     $post = $request->getPost();
     $form = $this->loginForm;
     $fm = $this->flashMessenger()->setNamespace('zfcuser-login-form')->getMessages();
     if (isset($fm[0])) {
         $this->loginForm->setMessages(array('identity' => array($fm[0])));
     }
     if ($this->options->getUseRedirectParameterIfPresent()) {
         $redirect = $request->getQuery()->get('redirect', !empty($post['redirect']) ? $post['redirect'] : false);
     } else {
         $redirect = false;
     }
     if (!$request->isPost()) {
         return array('loginForm' => $form, 'redirect' => $redirect, 'enableRegistration' => $this->options->getEnableRegistration());
     }
     $form->setData($post);
     if (!$form->isValid()) {
         $this->flashMessenger()->setNamespace('zfcuser-login-form')->addMessage($this->failedLoginMessage);
         return $this->redirect()->toUrl($this->url()->fromRoute(static::ROUTE_LOGIN) . ($redirect ? '?redirect=' . rawurlencode($redirect) : ''));
     }
     // clear adapters
     $this->zfcUserAuthentication()->getAuthAdapter()->resetAdapters();
     $this->zfcUserAuthentication()->getAuthService()->clearIdentity();
     return $this->forward()->dispatch(static::CONTROLLER_NAME, array('action' => 'authenticate'));
 }
開發者ID:bladehr8,項目名稱:bowhunter2015,代碼行數:33,代碼來源:UserController.php

示例2: testCorrectInputDataMerging

 public function testCorrectInputDataMerging()
 {
     $this->disablePhpUploadCapabilities();
     $form = new Form();
     $form->add(['name' => 'collection', 'type' => 'collection', 'options' => ['target_element' => new TestAsset\TestFieldset('target'), 'count' => 2]]);
     copy(__DIR__ . '/TestAsset/nullfile', __DIR__ . '/TestAsset/nullfile_copy');
     $request = $this->request;
     $request->setMethod('POST');
     $request->setPost(new Parameters(['collection' => [0 => ['text' => 'testvalue1'], 1 => ['text' => '']]]));
     $request->setFiles(new Parameters(['collection' => [0 => ['file' => ['name' => 'test.jpg', 'type' => 'image/jpeg', 'size' => 20480, 'tmp_name' => __DIR__ . '/TestAsset/nullfile_copy', 'error' => UPLOAD_ERR_OK]]]]));
     $this->controller->dispatch($this->request, $this->response);
     $plugin = $this->plugin;
     $plugin($form, '/test/getPage', true);
     $this->assertFalse($form->isValid());
     $data = $form->getData();
     // @codingStandardsIgnoreStart
     $this->assertEquals(['collection' => [0 => ['text' => 'testvalue1', 'file' => ['name' => 'test.jpg', 'type' => 'image/jpeg', 'size' => 20480, 'tmp_name' => __DIR__ . DIRECTORY_SEPARATOR . 'TestAsset' . DIRECTORY_SEPARATOR . 'testfile.jpg', 'error' => 0]], 1 => ['text' => null, 'file' => null]]], $data);
     // @codingStandardsIgnoreEnd
     $this->assertFileExists($data['collection'][0]['file']['tmp_name']);
     unlink($data['collection'][0]['file']['tmp_name']);
     $messages = $form->getMessages();
     $this->assertTrue(isset($messages['collection'][1]['text'][NotEmpty::IS_EMPTY]));
     $requiredFound = false;
     foreach ($messages['collection'][1]['file'] as $message) {
         if (strpos($message, 'Value is required') === 0) {
             $requiredFound = true;
             break;
         }
     }
     $this->assertTrue($requiredFound, '"Required" message was not found in validation failure messages');
 }
開發者ID:zendframework,項目名稱:zend-mvc-plugin-fileprg,代碼行數:31,代碼來源:FilePrgDataMergingTest.php

示例3: testEmptyFormNameShouldNotRenderEmptyFormId

 public function testEmptyFormNameShouldNotRenderEmptyFormId()
 {
     $form = new Form();
     $form->setMethod('post')->setAction('/foo/bar')->setView($this->getView());
     $html = $form->render();
     $this->assertNotContains('id=""', $html, $html);
 }
開發者ID:bradley-holt,項目名稱:zf2,代碼行數:7,代碼來源:FormDecoratorTest.php

示例4: getFilter

 /**
  * @param null $name
  * @return \Zend\Form\ElementInterface|Form
  */
 public function getFilter($name = null)
 {
     if (!empty($name)) {
         return $this->filter->get($name);
     }
     return $this->filter;
 }
開發者ID:sebaks,項目名稱:Translate,代碼行數:11,代碼來源:ListViewModel.php

示例5: addCSRFElement

 public function addCSRFElement($name, $value)
 {
     $csrf = new \Zend\Form\Element\Hidden($name);
     $csrf->setValue($value);
     $this->form->add($csrf);
     return $this;
 }
開發者ID:caseypage,項目名稱:php-ssrs-1,代碼行數:7,代碼來源:ZendFramework2.php

示例6: injectValidatorPluginManager

 public static function injectValidatorPluginManager(Form $form, ServiceLocatorInterface $sl)
 {
     $plugins = $sl->get('ValidatorManager');
     $chain = new FilterChain();
     $chain->setPluginManager($plugins);
     $form->getFormFactory()->getInputFilterFactory()->setDefaultFilterChain($chain);
 }
開發者ID:soflomo,項目名稱:common,代碼行數:7,代碼來源:FormUtils.php

示例7: add

 /**
  * @param \Zend\Form\Form $form
  * @param $data
  * @return Entity\Comment|null
  * @throws \Exception
  */
 public function add(\Zend\Form\Form $form, $data)
 {
     $serviceLocator = $this->getServiceLocator();
     $entityManager = $serviceLocator->get('Doctrine\\ORM\\EntityManager');
     $entityType = $entityManager->getRepository('\\Comment\\Entity\\EntityType')->findOneByAlias($data['alias']);
     if (!$entityType) {
         throw new EntityNotFoundException();
     }
     $form->setData($data);
     if ($form->isValid()) {
         if ($entityType->getIsEnabled()) {
             $data = $form->getData();
             $comment = new Entity\Comment();
             $comment->setEntityType($entityType);
             $user = $serviceLocator->get('Zend\\Authentication\\AuthenticationService')->getIdentity()->getUser();
             $comment->setUser($user);
             $comment->setComment($data['comment']);
             $entityManager->getConnection()->beginTransaction();
             try {
                 $hydrator = new DoctrineHydrator($entityManager);
                 $hydrator->hydrate($data, $comment);
                 $entityType->getComments()->add($comment);
                 $entityManager->persist($comment);
                 $entityManager->persist($entityType);
                 $entityManager->flush();
                 $entityManager->getConnection()->commit();
                 return $comment;
             } catch (\Exception $e) {
                 $entityManager->getConnection()->rollback();
                 throw $e;
             }
         }
     }
     return null;
 }
開發者ID:zfury,項目名稱:cmf,代碼行數:41,代碼來源:Comment.php

示例8: create

 /**
  * Create a new post
  *
  * @param array $data
  * @param \Zend\Form\Form $form
  * @return bool
  */
 public function create($data, &$form)
 {
     $post = new PostEntity();
     $em = $this->getEntityManager();
     $form->bind($post);
     $form->setData($data);
     if (!$form->isValid()) {
         return false;
     }
     // we rename the file with a unique name
     $newName = FileUtilService::rename($data['post']['thumbnail'], 'images/posts', "post");
     foreach (PostEntity::$thumbnailVariations as $variation) {
         $result = FileUtilService::resize($newName, 'images/posts', $variation["width"], $variation["height"]);
         if (!$result) {
             $this->message = $result;
             return false;
         }
     }
     $post->setThumbnail($newName);
     $post->setPostDate("now");
     $post->setUrl($this->getPostUrl($post));
     try {
         $em->persist($post);
         $em->flush();
         $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_POST_CREATED"]);
         return true;
     } catch (\Exception $e) {
         $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_POST_NOT_CREATED"]);
         return false;
     }
 }
開發者ID:JoshBour,項目名稱:karolina,代碼行數:38,代碼來源:PostService.php

示例9: getModel

 protected function getModel()
 {
     // Dependências
     $form = new Form();
     $inputFilter = new InputFilter();
     $formSearch = new Form();
     $inputFilterSearch = new InputFilter();
     $persistence = $this->getMock('Balance\\Model\\Persistence\\PersistenceInterface');
     // Parâmetro
     $form->add(new Text('id'));
     $inputFilter->add(new Input('id'));
     // Parâmetro
     $form->add(new Text('foo'));
     $inputFilter->add(new Input('foo'));
     // Pesquisa: Palavras Chave
     $formSearch->add(new Text('keywords'));
     $inputFilterSearch->add(new Input('keywords'));
     // Configurações
     $form->setInputFilter($inputFilter);
     $formSearch->setInputFilter($inputFilterSearch);
     // Inicialização
     $model = new Model($persistence);
     // Formulários
     $model->setForm($form)->setFormSearch($formSearch);
     // Apresentação
     return $model;
 }
開發者ID:wandersonwhcr,項目名稱:balance,代碼行數:27,代碼來源:ModelTest.php

示例10: create

 /**
  * Create a new image
  *
  * @param array $data
  * @param \Zend\Form\Form $form
  * @return bool
  */
 public function create($data, &$form)
 {
     $entity = new ImageEntity();
     $em = $this->getEntityManager();
     $form->bind($entity);
     $form->setData($data);
     if (!$form->isValid()) {
         return false;
     }
     // we rename the file with a unique name
     $newName = FileUtilService::rename($data['image']['image'], 'images/gallery', "gallery");
     foreach (ImageEntity::$thumbnailVariations as $variation) {
         $result = FileUtilService::resize($newName, 'images/gallery', $variation["width"], $variation["height"]);
         if (!$result) {
             $this->message = $result;
             return false;
         }
     }
     $entity->setImage($newName);
     try {
         $em->persist($entity);
         $em->flush();
         $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_IMAGE_CREATED"]);
         return true;
     } catch (\Exception $e) {
         $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_IMAGE_NOT_CREATED"]);
         return false;
     }
 }
開發者ID:JoshBour,項目名稱:karolina,代碼行數:36,代碼來源:ImageService.php

示例11: __invoke

 public function __invoke(Form $form, $action)
 {
     $form->setAttribute('method', 'post');
     $form->setAttribute('action', $action);
     $form->prepare();
     $view = $this->getView();
     $html = '';
     $html .= $view->form()->openTag($form);
     $html .= '<table class="default-table">';
     $formElements = $form->getElements();
     foreach ($formElements as $formElement) {
         if ($formElement instanceof Checkbox) {
             $html .= $view->formRowCheckbox($form, $formElement);
         } else {
             if ($formElement instanceof Submit) {
                 $html .= $view->formRowSubmit($form, $formElement);
             } else {
                 $html .= $view->formRowDefault($form, $formElement);
             }
         }
     }
     $html .= '</table>';
     $html .= $view->form()->closeTag();
     return $html;
 }
開發者ID:Mendim,項目名稱:ep3-bs,代碼行數:25,代碼來源:FormDefault.php

示例12: _recursivelyPrepareForm

 protected function _recursivelyPrepareForm(Form\Form $form)
 {
     $belongsTo = $form instanceof Form\Form ? $form->getElementsBelongTo() : null;
     $elementContent = '';
     $separator = $this->getSeparator();
     $translator = $form->getTranslator();
     $view = $form->getView();
     foreach ($form as $item) {
         $item->setView($view)->setTranslator($translator);
         if ($item instanceof Form\Element) {
             $item->setBelongsTo($belongsTo);
         } elseif ($item instanceof Form\Form) {
             if (!empty($belongsTo)) {
                 if ($item->isArray()) {
                     $name = $this->mergeBelongsTo($belongsTo, $item->getElementsBelongTo());
                     $item->setElementsBelongTo($name, true);
                 } else {
                     $item->setElementsBelongTo($belongsTo, true);
                 }
             }
             $this->_recursivelyPrepareForm($item);
         } elseif ($item instanceof Form\DisplayGroup) {
             if (!empty($belongsTo)) {
                 foreach ($item as $element) {
                     $element->setBelongsTo($belongsTo);
                 }
             }
         }
     }
 }
開發者ID:alab1001101,項目名稱:zf2,代碼行數:30,代碼來源:PrepareElements.php

示例13: create

 /**
  * @param  ServiceLocatorInterface $serviceLocator
  * @return FormInterface
  */
 public function create()
 {
     $formElementManager = $this->serviceManager->get('FormElementManager');
     $form = new Form();
     $form->add($formElementManager->get('Wizard\\Form\\Element\\Button\\Previous'))->add($formElementManager->get('Wizard\\Form\\Element\\Button\\Next'))->add($formElementManager->get('Wizard\\Form\\Element\\Button\\Valid'))->add($formElementManager->get('Wizard\\Form\\Element\\Button\\Cancel'));
     return $form;
 }
開發者ID:Tribalx,項目名稱:Wizard,代碼行數:11,代碼來源:FormFactory.php

示例14: addExtSubForm

 public function addExtSubForm(ZendForm $form, $name)
 {
     $extsForm = $this->getExtSubForm();
     $form->setIsArray(true);
     $form->removeDecorator('FormDecorator');
     $extsForm->addSubForm($form, $name);
 }
開發者ID:ashimidashajia,項目名稱:zendstore,代碼行數:7,代碼來源:Form.php

示例15: __invoke

 public function __invoke(Form $form)
 {
     $form->setAttribute('class', self::DEFAULT_FORM_CLASS);
     foreach ($form->getElements() as $element) {
         /*
          * controls how far the form indents into
          * the page using Twitter:Bootstrap CSS
          *
          */
         $defLabelAttributes = array('class' => self::DEFAULT_LABEL_CLASS);
         $element->setLabelAttributes($defLabelAttributes);
         $element->setAttribute('class', self::DEFAULT_INPUT_CLASS);
         /*
          * set the id attribute of all inputs to be equal to their names
          *
          * makes life simple when trying to make the view
          * dynamic
          */
         $element->setAttribute('id', $element->getName());
     }
     /*
      * the submit button is a little different, it uses
      * a button class to proper rendering
      *
      */
     $form->get('submit')->setAttribute('class', self::DEFAULT_SUBMIT_BUTTON_CLASS);
     return $form;
 }
開發者ID:decmade,項目名稱:zendAbacAcl,代碼行數:28,代碼來源:AddBootstrapFormAttributes.php


注:本文中的Zend\Form\Form類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。