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


PHP ElementInterface::useHiddenElement方法代码示例

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


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

示例1: render

 /**
  * Render a form <input> element from the provided $element
  *
  * @param  ElementInterface $element
  * @throws \Zend\Form\Exception\DomainException
  * @return string
  */
 public function render(ElementInterface $element)
 {
     if (!$element instanceof CheckboxElement) {
         throw new Exception\InvalidArgumentException(sprintf('%s requires that the element is of type Zend\\Form\\Element\\Checkbox', __METHOD__));
     }
     $name = $element->getName();
     if (empty($name) && $name !== 0) {
         throw new Exception\DomainException(sprintf('%s requires that the element has an assigned name; none discovered', __METHOD__));
     }
     $checkedValue = $element->getCheckedValue();
     $uncheckedValue = $element->getUncheckedValue();
     $useHiddenElement = $element->useHiddenElement();
     $attributes = $element->getAttributes();
     $attributes['name'] = $name;
     $attributes['checked'] = '';
     $attributes['type'] = $this->getInputType();
     $closingBracket = $this->getInlineClosingBracket();
     $value = $element->getValue();
     if ($value === $checkedValue) {
         $attributes['checked'] = 'checked';
     }
     $attributes['value'] = $checkedValue;
     $rendered = sprintf('<input %s%s', $this->createAttributesString($attributes), $closingBracket);
     if ($useHiddenElement) {
         $hiddenAttributes = array('name' => $attributes['name'], 'value' => $uncheckedValue);
         $rendered = sprintf('<input type="hidden" %s%s', $this->createAttributesString($hiddenAttributes), $closingBracket) . $rendered;
     }
     return $rendered;
 }
开发者ID:Rovak,项目名称:zf2,代码行数:36,代码来源:FormCheckbox.php

示例2: render

 /**
  * Render a form <input> element from the provided $element
  *
  * @param  ElementInterface $element
  * @throws Exception\InvalidArgumentException
  * @throws Exception\DomainException
  * @return string
  */
 public function render(ElementInterface $element)
 {
     if (!$element instanceof CheckboxElement) {
         throw new Exception\InvalidArgumentException(sprintf('%s requires that the element is of type Zend\\Form\\Element\\Checkbox', __METHOD__));
     }
     $name = $element->getName();
     if (empty($name) && $name !== 0) {
         throw new Exception\DomainException(sprintf('%s requires that the element has an assigned name; none discovered', __METHOD__));
     }
     $attributes = $element->getAttributes();
     $attributes['name'] = $name;
     $attributes['type'] = $this->getInputType();
     $attributes['value'] = $element->getCheckedValue();
     $attributes['class'] = 'sr-only';
     $closingBracket = $this->getInlineClosingBracket();
     if ($element->isChecked()) {
         $attributes['checked'] = 'checked';
     }
     $input = sprintf('<input %s%s', $this->createAttributesString($attributes), $closingBracket);
     $label = $element->getLabel();
     $rendered = '<div class="checkbox"><label class="checkbox-custom" data-initialize="checkbox">' . $input . '<span class="checkbox-label">' . $label . '</span>' . '</label></div>';
     if ($element->useHiddenElement()) {
         $hiddenAttributes = array('name' => $attributes['name'], 'value' => $element->getUncheckedValue());
         $rendered = sprintf('<input type="hidden" %s%s', $this->createAttributesString($hiddenAttributes), $closingBracket) . $rendered;
     }
     return $rendered;
 }
开发者ID:khinmyatkyi,项目名称:Office_Management,代码行数:35,代码来源:FormCheckBox.php

示例3: render

 /**
  * Render a form <input> element from the provided $element
  *
  * @param  ElementInterface $element
  * @throws \Zend\Form\Exception\DomainException
  * @return string
  */
 public function render(ElementInterface $element)
 {
     $name = $element->getName();
     if (empty($name)) {
         throw new Exception\DomainException(sprintf('%s requires that the element has an assigned name; none discovered', __METHOD__));
     }
     $attributes = $element->getAttributes();
     $attributes['name'] = $name;
     $attributes['checked'] = '';
     $attributes['type'] = $this->getInputType();
     $closingBracket = $this->getInlineClosingBracket();
     if (isset($attributes['value']) && $attributes['value'] == $element->getCheckedValue()) {
         $attributes['checked'] = 'checked';
     }
     $attributes['value'] = $element->getCheckedValue();
     $rendered = sprintf('<input %s%s', $this->createAttributesString($attributes), $closingBracket);
     $useHiddenElement = $element->useHiddenElement();
     if ($useHiddenElement) {
         $hiddenAttributes = array('name' => $attributes['name'], 'value' => $element->getUncheckedValue());
         $rendered = sprintf('<input type="hidden" %s%s', $this->createAttributesString($hiddenAttributes), $closingBracket) . $rendered;
     }
     return $rendered;
 }
开发者ID:robertodormepoco,项目名称:zf2,代码行数:30,代码来源:FormCheckbox.php

示例4: render

 /**
  * Render a form <input> element from the provided $element
  *
  * @param  ElementInterface $element
  * @param String $buttonContent
  * @throws Exception\DomainException
  * @return string
  */
 public function render(ElementInterface $element, $buttonContent = null)
 {
     if (null === $buttonContent) {
         $buttonContent = $element->getLabel();
         if (null === $buttonContent) {
             throw new Exception\DomainException(sprintf('%s expects either button content as the second argument, ' . 'or that the element provided has a label value; neither found', __METHOD__));
         }
         if (null !== ($translator = $this->getTranslator())) {
             $buttonContent = $translator->translate($buttonContent, $this->getTranslatorTextDomain());
         }
         $element->setLabel('');
     }
     $value = $element->getValue();
     $checkedBoole = $value == 1 || $value == 'on';
     $checkedClass = $checkedBoole ? 'active"' : '';
     $hiddenElement = '';
     if ($element->useHiddenElement()) {
         $hiddenAttributes = ['name' => $element->getName(), 'value' => $element->getUncheckedValue()];
         $hiddenElement = sprintf('<input type="hidden" %s%s', $this->createAttributesString($hiddenAttributes), '>');
         $element->setUseHiddenElement(false);
     }
     $buttonContent = $hiddenElement . PHP_EOL . '<div class="btn-group" data-toggle="buttons">' . PHP_EOL . '<label class="btn btn-default ' . $checkedClass . '">' . PHP_EOL . parent::render($element) . $buttonContent . PHP_EOL . '</label>' . PHP_EOL . '</div>' . PHP_EOL;
     return $buttonContent;
 }
开发者ID:cross-solution,项目名称:yawik,代码行数:32,代码来源:ToggleButton.php


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