本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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');
}
示例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);
}
示例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'));
}