本文整理汇总了PHP中Zend\Form\Form::has方法的典型用法代码示例。如果您正苦于以下问题:PHP Form::has方法的具体用法?PHP Form::has怎么用?PHP Form::has使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Form\Form
的用法示例。
在下文中一共展示了Form::has方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getForm
/**
* {@inheritDoc}
*/
public function getForm()
{
$currentStep = $this->getCurrentStep();
if (!$currentStep) {
return;
}
if (null === $this->form) {
$this->form = $this->formFactory->create();
$this->form->setAttribute('action', sprintf('?%s=%s', $this->getOptions()->getTokenParamName(), $this->getUniqueId()));
if (!$this->getSteps()->getPrevious($currentStep)) {
$this->form->remove('previous');
}
if (!$this->getSteps()->getNext($currentStep)) {
$this->form->remove('next');
} else {
$this->form->remove('valid');
}
}
$stepForm = $currentStep->getForm();
if ($stepForm instanceof Form) {
if ($this->form->has(self::STEP_FORM_NAME)) {
$this->form->remove(self::STEP_FORM_NAME);
}
$stepForm->setName(self::STEP_FORM_NAME);
$stepForm->populateValues($currentStep->getData());
$this->form->add($stepForm);
}
return $this->form;
}
示例2: testCanAddFieldsetsUsingSpecs
public function testCanAddFieldsetsUsingSpecs()
{
$this->form->add(array('type' => 'Zend\\Form\\Fieldset', 'name' => 'foo', 'attributes' => array('type' => 'fieldset', 'class' => 'foo-class', 'data-js-type' => 'my.form.fieldset')));
$this->assertTrue($this->form->has('foo'));
$fieldset = $this->form->get('foo');
$this->assertInstanceOf('Zend\\Form\\FieldsetInterface', $fieldset);
$this->assertEquals('foo', $fieldset->getName());
$this->assertEquals('fieldset', $fieldset->getAttribute('type'));
$this->assertEquals('foo-class', $fieldset->getAttribute('class'));
$this->assertEquals('my.form.fieldset', $fieldset->getAttribute('data-js-type'));
}
示例3: testAddRemove
public function testAddRemove()
{
$form = clone $this->form;
$this->assertEquals($form, $this->form);
$file = new Element\File('file_resource');
$this->form->add($file);
$this->assertTrue($this->form->has('file_resource'));
$this->assertNotEquals($form, $this->form);
$this->form->remove('file_resource');
$this->assertEquals($form, $this->form);
}
示例4: __invoke
/**
* @param Form $form
* @param array $fields
* @param array $overwrite
*
* @return string
*/
public function __invoke($form, $fields, $overwrite = null)
{
if ($overwrite === null) {
$overwrite = array();
}
if (!is_array($fields)) {
$fields = array($fields);
}
$html = '';
foreach ($fields as $i => $field) {
$addon = '';
if (!is_int($i)) {
$addon = $field;
$field = $i;
}
if (!$form->has($field)) {
throw new \Exception(sprintf('Element doesn\'t exists \'%s\'', $field));
}
$element = $form->get($field);
$type = strtolower($element->getAttribute('type'));
if (array_key_exists($field, $overwrite)) {
if ($type === 'submit') {
$element->setValue($overwrite[$field]);
} else {
$element->setOption('label', $overwrite[$field]);
}
}
$plugin = $this->getPlugin($type);
$prefix = '';
$encaps = '%s';
switch ($type) {
case 'checkbox':
$encaps = sprintf("<div class=\"checkbox-block\">%s</div><div class=\"col-xs-10\">%s</div>", '%s', $this->getLabel($element));
break;
case "textarea":
if (preg_match('/readonly/i', $element->getAttribute('class'))) {
$prefix = '<p class="toggle-edit"><a href="#">Edit</a></p><iframe style="width:200px; height:100px; display: none;"></iframe>';
}
default:
$prefix .= $this->getLabel($element);
break;
}
$input = $plugin($element);
if (!empty($prefix)) {
$prefix = sprintf($this->labelBlock, $prefix);
}
$html .= sprintf($this->format, $element->getName(), $prefix, sprintf($encaps, $input), $addon, $this->buildErrorMessage($element));
}
return $html;
}
示例5: remove
/**
* {@inheritDoc}
*/
public function remove($elementOrFieldset)
{
if (!parent::has($elementOrFieldset)) {
if ($elementOrFieldset === 'captcha') {
$elementOrFieldset = $this->getCaptchaElementName();
} elseif ($elementOrFieldset === 'csrf') {
$elementOrFieldset = $this->getCsrfElementName();
}
}
return parent::remove($elementOrFieldset);
}