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


PHP Form::addElement方法代码示例

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


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

示例1: __invoke

 public function __invoke(FormModel $model, $route)
 {
     $form = new ZendForm();
     foreach ($model->getElements() as $element) {
         $type = $element->getType();
         $name = $element->getName();
         $options = (array) Json::decode($element->getOptions());
         $form->addElement($type, $name, $options);
     }
     $form->addElement('hidden', IndexController::ID, array('value' => $model->getId()));
     $url = $this->getView()->url(array(), array('name' => $route . '/send'));
     $form->setView($this->getView())->setAction($url);
     return $form;
 }
开发者ID:bb-drummer,项目名称:Zcmf,代码行数:14,代码来源:Form.php

示例2: getForm

 public function getForm()
 {
     $form = new Form();
     $form->addElement('text', 'foo')->addElement('text', 'bar')->addElement('text', 'baz')->addElement('text', 'bat');
     $subForm = new SubForm();
     $subForm->addElement('text', 'foo')->addElement('text', 'bar')->addElement('text', 'baz')->addElement('text', 'bat');
     $form->addDisplayGroup(array('foo', 'bar'), 'foobar')->addSubForm($subForm, 'sub')->setView(new View\PhpRenderer());
     return $form;
 }
开发者ID:rafalwrzeszcz,项目名称:zf2,代码行数:9,代码来源:DojoTest.php

示例3: testCaptchaShouldRenderFullyQualifiedElementName

 /**
  * @group ZF-4038
  */
 public function testCaptchaShouldRenderFullyQualifiedElementName()
 {
     $form = new Form();
     $form->addElement($this->element)->setElementsBelongTo('bar');
     $html = $form->render(new View());
     $this->assertContains('name="bar[foo', $html, $html);
     $this->assertContains('id="bar-foo-', $html, $html);
     $this->form = $form;
 }
开发者ID:bradley-holt,项目名称:zf2,代码行数:12,代码来源:CaptchaTest.php

示例4: setupForm

 public function setupForm()
 {
     $form1 = new SubForm();
     $form1->addElement('text', 'foo', array('label' => 'Sub Foo: ', 'required' => true, 'validators' => array('NotEmpty', 'Alpha')))->addElement('text', 'bar', array('label' => 'Sub Bar: ', 'required' => true, 'validators' => array('Alpha', 'Alnum')));
     $form2 = new Form();
     $form2->addElement('text', 'foo', array('label' => 'Master Foo: ', 'required' => true, 'validators' => array('NotEmpty', 'Alpha')))->addElement('text', 'bar', array('required' => true, 'validators' => array('Alpha', 'Alnum')))->addSubForm($form1, 'sub');
     $form2->isValid(array('foo' => '', 'bar' => 'foo 2 u 2', 'sub' => array('foo' => '', 'bar' => 'foo 2 u 2')));
     $form2->setView($this->getView());
     $this->decorator->setElement($form2);
     $this->form = $form2;
     return $form2;
 }
开发者ID:navtis,项目名称:xerxes-pazpar2,代码行数:12,代码来源:FormErrorsTest.php

示例5: addElement

 public function addElement($element, $name = null, $options = null)
 {
     if (is_string($element)) {
         $element = strtolower($element);
         if (isset($this->customeElementDecorators[$element])) {
             $baseOptions = $this->customeElementDecorators[$element];
             if (!isset($options['decorators'])) {
                 if (isset($baseOptions['decorators'])) {
                     $decorators = $baseOptions['decorators'];
                     $options['decorators'] = isset($options['decorators']) ? array_merge($options['decorators'], $decorators) : $decorators;
                 } else {
                     $options['decorators'] = $this->customeElementDecoratorDefault;
                 }
             }
             if (isset($baseOptions['helper'])) {
                 $element = $baseOptions['helper'];
             }
             if (isset($baseOptions['options'])) {
                 foreach ($baseOptions['options'] as $key => $value) {
                     if (!isset($options[$key])) {
                         $options[$key] = null;
                     }
                     switch ($key) {
                         case 'class':
                             $options[$key] .= ' ' . $baseOptions['options'][$key];
                             break;
                         case 'rows':
                             $options[$key] = null !== $options[$key] ?: $baseOptions['options'][$key];
                             break;
                         default:
                             throw new \InvalidArgumentException('Merging option key "' . $key . '" is not defained');
                     }
                 }
             }
             return parent::addElement($element, $name, $options);
         }
     }
     return parent::addElement($element, $name, $options);
 }
开发者ID:sotodiego,项目名称:zf2-twitter-bootstrap-module,代码行数:39,代码来源:Form.php

示例6: 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

示例7: testDtDdElementsWithLabelGetUniqueId

 /**
  * @group ZF-2950
  */
 public function testDtDdElementsWithLabelGetUniqueId()
 {
     $form = new Form();
     $form->setView($this->getView());
     $fooElement = new \Zend\Form\Element\Text('foo');
     $fooElement->setLabel('Foo');
     $form->addElement($fooElement);
     $html = $form->render();
     $this->assertContains('<dt id="foo-label">', $html);
     $this->assertContains('<dd id="foo-element">', $html);
 }
开发者ID:rexmac,项目名称:zf2,代码行数:14,代码来源:FormTest.php

示例8: testCustomLabelDecorator

 /**
  * @group ZF-9682
  */
 public function testCustomLabelDecorator()
 {
     $form = new Form();
     $form->addElementPrefixPath('My\\Decorator', __DIR__ . '/../TestAsset/decorators/', 'decorator');
     $form->addElement($this->element);
     $element = $form->getElement('foo');
     $this->assertInstanceOf('My\\Decorator\\Label', $element->getDecorator('Label'));
 }
开发者ID:rafalwrzeszcz,项目名称:zf2,代码行数:11,代码来源:RadioTest.php


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