php Zend-Form-Form类(方法)实例源码

下面列出了php Zend-Form-Form 类(方法)源码代码实例,从而了解它的用法。

作者:bladehr    项目:bowhunter201   
/**
  * 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'));
 }

作者:zendframewor    项目:zend-mvc-plugin-filepr   
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');
 }

作者:bradley-hol    项目:zf   
public function testEmptyFormNameShouldNotRenderEmptyFormId()
 {
     $form = new Form();
     $form->setMethod('post')->setAction('/foo/bar')->setView($this->getView());
     $html = $form->render();
     $this->assertNotContains('id=""', $html, $html);
 }

作者:sebak    项目:Translat   
/**
  * @param null $name
  * @return \Zend\Form\ElementInterface|Form
  */
 public function getFilter($name = null)
 {
     if (!empty($name)) {
         return $this->filter->get($name);
     }
     return $this->filter;
 }

作者:caseypag    项目:php-ssrs-   
public function addCSRFElement($name, $value)
 {
     $csrf = new \Zend\Form\Element\Hidden($name);
     $csrf->setValue($value);
     $this->form->add($csrf);
     return $this;
 }

作者:soflom    项目:commo   
public static function injectValidatorPluginManager(Form $form, ServiceLocatorInterface $sl)
 {
     $plugins = $sl->get('ValidatorManager');
     $chain = new FilterChain();
     $chain->setPluginManager($plugins);
     $form->getFormFactory()->getInputFilterFactory()->setDefaultFilterChain($chain);
 }

作者:zfur    项目:cm   
/**
  * @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;
 }

作者:JoshBou    项目:karolin   
/**
  * 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;
     }
 }

作者:wandersonwhc    项目:balanc   
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;
 }

作者:JoshBou    项目:karolin   
/**
  * 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;
     }
 }

作者:Mendi    项目:ep3-b   
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;
 }

作者:alab100110    项目:zf   
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);
                 }
             }
         }
     }
 }

作者:Tribal    项目:Wizar   
/**
  * @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;
 }

作者:ashimidashaji    项目:zendstor   
public function addExtSubForm(ZendForm $form, $name)
 {
     $extsForm = $this->getExtSubForm();
     $form->setIsArray(true);
     $form->removeDecorator('FormDecorator');
     $extsForm->addSubForm($form, $name);
 }

作者:decmad    项目:zendAbacAc   
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;
 }

作者:huanhuashenglin    项目:ipc2013-testin   
/**
  * Outputs message depending on flag
  *
  * @return string
  */
 public function __invoke(Form $form, $url, $class = 'form-horizontal')
 {
     $form->setAttribute('action', $url);
     $form->setAttribute('class', $class);
     $form->prepare();
     $output = $this->getView()->form()->openTag($form);
     $submitElements = array();
     foreach ($form as $element) {
         if ($element instanceof Submit) {
             $submitElements[] = $element;
         } elseif ($element instanceof Csrf || $element instanceof Hidden) {
             $output .= $this->getView()->formElement($element);
         } else {
             $element->setLabelAttributes(array('class' => 'control-label'));
             $output .= '<div class="control-group">';
             $output .= $this->getView()->formLabel($element);
             $output .= '<div class="controls">';
             $output .= $this->getView()->formElement($element);
             $output .= $this->getView()->formElementErrors($element);
             $output .= '</div>';
             $output .= '</div>';
         }
     }
     $output .= '<div class="form-actions">';
     foreach ($submitElements as $element) {
         $output .= $this->getView()->formElement($element) . '&nbsp;';
     }
     $output .= '</div>';
     $output .= $this->getView()->form()->closeTag();
     return $output;
 }

作者:sanPgu    项目:SupportCoursZF   
public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $form = new Form();
     $form->add(new \MiniModule\Form\Element\Login(), array('priority' => 1));
     $form->add(new Submit('submit'));
     return $form;
 }

作者:suitedJ    项目:ZfcTwitterBootstra   
/**
  * Display a Form
  *
  * @param  \Zend\Form\Form $form
  * @return string
  */
 public function __invoke(ZendForm $form)
 {
     $form->prepare();
     $html = $this->getFormHelper()->openTag($form);
     $html .= $this->render($form->getIterator());
     return $html . $this->getFormHelper()->closeTag();
 }

作者:gridguy    项目:cor   
/**
  * Get step model
  *
  * @param string $step
  * @return \Core\View\Model\WizardStep
  */
 protected function getStep($step)
 {
     $store = $this->getStore();
     $formSrv = $this->getServiceLocator()->get('Form');
     if ($step == $this->startStep) {
         $form = $formSrv->get('Grid\\Paragraph\\CreateWizard\\Start');
         $model = new StartStep(array('textDomain' => 'paragraph'));
     } else {
         $store['type'] = $step;
         $form = new Form();
         $create = $formSrv->get('Grid\\Paragraph\\Meta\\Create');
         $model = new WizardStep(array('textDomain' => 'paragraph'), array('finish' => true, 'next' => 'finish'));
         if ($create->has($step)) {
             foreach ($create->get($step) as $element) {
                 $form->add($element);
             }
         } else {
             $edit = $formSrv->get('Grid\\Paragraph\\Meta\\Edit');
             if ($edit->has($step)) {
                 foreach ($edit->get($step) as $element) {
                     $form->add($element);
                 }
             } else {
                 $model->setOption('skip', true);
             }
         }
     }
     return $model->setStepForm($form);
 }

作者:adaca    项目:3agest-prototyp   
/**
  * @param mixed $model
  */
 public function setModel($model)
 {
     $modelClass = get_class($model);
     $this->form = $this->annotationBuilder->createForm($modelClass);
     $this->form->bind($model);
     $this->setVariables(['form' => $this->form, 'object' => $model, 'title' => $this->getFieldSetTitle($model)]);
     $this->buildFormViewModel($this->form, $this);
 }


问题


面经


文章

微信
公众号

扫码关注公众号