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


PHP FormInterface::setAttribute方法代码示例

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


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

示例1: __invoke

 /**
  * Outputs message depending on flag
  *
  * @param FormInterface $form
  * @param array         $staticElements
  * @param null          $formClass
  *
  * @return string
  */
 public function __invoke(FormInterface $form, array $staticElements = [], $formClass = null)
 {
     $submitElements = [];
     /** @var Form $form */
     $form->setAttribute('role', 'form');
     if ($formClass == 'form-inline') {
         $form->setAttribute('class', $formClass . ' pull-right');
     } elseif ($formClass) {
         $form->setAttribute('class', $formClass);
     } else {
         $formClass = $form->getAttribute('class');
     }
     $form->prepare();
     $output = $this->getView()->form()->openTag($form);
     foreach ($staticElements as $element) {
         $viewModel = new ViewModel();
         $viewModel->setVariable('label', $element['label']);
         $viewModel->setVariable('value', $element['value']);
         $viewModel->setTemplate('travello-view-helper/widget/bootstrap-form-static');
         $output .= $this->getView()->render($viewModel);
     }
     list($output, $submitElements) = $this->renderElements($form, $formClass, $output, $submitElements);
     if ($formClass == 'form-inline') {
         $template = 'bootstrap-form-submit-inline';
     } else {
         $template = 'bootstrap-form-submit';
     }
     $viewModel = new ViewModel();
     $viewModel->setVariable('submitElements', $submitElements);
     $viewModel->setTemplate('travello-view-helper/widget/' . $template);
     $output .= $this->getView()->render($viewModel);
     $output .= $this->getView()->form()->closeTag();
     return $output;
 }
开发者ID:RalfEggert,项目名称:travello-view-helper,代码行数:43,代码来源:BootstrapForm.php

示例2: prepareElement

 public function prepareElement(FormInterface $form)
 {
     $form->setAttribute('class', ($this->isMultiple() ? 'multi' : 'single') . '-file-upload');
     $form->setAttribute('data-is-empty', null === $this->getValue());
     $this->form = $form;
     parent::prepareElement($form);
 }
开发者ID:bitrecruiter,项目名称:CrossApplicantManager,代码行数:7,代码来源:FileUpload.php

示例3: renderForAjax

    /**
     * Render form with ajax submit
     * @see \Zend\Form\View\Helper\Form::render()
     * @param \Zend\Form\FormInterface $oForm
     * @param string $sFormLayout : default 'horizontal'
     * @return string
     */
    public function renderForAjax(\Zend\Form\FormInterface $oForm, $sFormLayout = \TwbBundle\Form\View\Helper\TwbBundleForm::LAYOUT_HORIZONTAL, $bAjax = false)
    {
        $sAfter = '
			if(document.id){
				try{
		';
        if (!$oForm->getAttribute('action')) {
            $oForm->setAttribute('action', $this->getRequest()->getUri()->normalize());
        }
        if (!$oForm->getAttribute('id')) {
            $oForm->setAttribute('id', $oForm->getName());
        }
        if ($oForm->getAttribute('enctype') === 'multipart/form-data') {
            $sAfter .= '
					var eForm = document.id(' . $this->getEscapeJsonHelper()->__invoke($oForm->getAttribute('id')) . ');
					eForm.iFrameFormRequest({
				        onRequest: function(){
							if(eForm.validate())eForm.spin();
						},
						onComplete: function(sText){
							var sJavascript = null;
							var sHtml =	sText.stripScripts(function(sScript){
								sJavascript = sScript;
							});
							var aMatches = sHtml.match(/<body[^>]*>([\\s\\S]*?)<\\/body>/i);
							if(aMatches)sHtml = aMatches[1];
				           	var eContainer = eForm.getParent().empty().set(\'html\',sHtml);
							if(sJavascript)Browser.exec(sJavascript);
							eForm.unspin();
							window.behavior.apply(eContainer.getParent(),true);
				        },
				        onFailure: function(){
				        	alert(oController.translate(\'error_occurred\'));
				        }
				    });
		';
        } else {
            $sAfter .= '
					var eForm = document.id(' . $this->getEscapeJsonHelper()->__invoke($oForm->getAttribute('id')) . ');
					eForm.get(\'validator\').addEvent(\'formValidate\',function(bIsValid){
						if(bIsValid)new Form.Request(eForm,eForm.getParent()).send();
					});
			';
            $oForm->setAttribute('onsubmit', 'return false;');
        }
        $sAfter .= '
				}
			    catch(oException){
					if(oController != null)alert(' . $this->getEscapeJsonHelper()->__invoke($this->getTranslator()->translate('error_occurred')) . ');
	    		}
			}
		';
        return parent::render($oForm, $sFormLayout) . PHP_EOL . '<script type="text/javascript">' . $sAfter . '</script>';
    }
开发者ID:zf2-boiler-app,项目名称:app-display,代码行数:61,代码来源:FormHelper.php

示例4: openTag

 /**
  * {@inheritDoc}
  */
 public function openTag(FormInterface $form = null)
 {
     if ($form) {
         if (!$form->hasAttribute('role')) {
             $form->setAttribute('role', 'form');
         }
         $class = $form->getAttribute('class');
         if (strpos($class, 'form-horizontal') === false && strpos($class, 'form-inline') === false) {
             $form->setAttribute('class', trim("{$this->defaultClass} {$class}"));
         }
     }
     return parent::openTag($form);
 }
开发者ID:coolms,项目名称:twbs,代码行数:16,代码来源:Form.php

示例5: renderBare

 /**
  * Render a form from the provided $form,
  *
  * @param FormInterface $form
  * @param string $layout
  * @param array $parameter
  * @return string
  */
 public function renderBare(FormInterface $form, $layout = self::LAYOUT_INLINE, $parameter = array())
 {
     $renderer = $this->getView();
     $headscript = $renderer->plugin('headscript');
     $basepath = $renderer->plugin('basepath');
     $headscript->appendFile($basepath('Core/js/core.spinnerbutton.js'))->appendFile($basepath('js/select2.min.js'))->appendFile($basepath('Core/js/core.forms.js'));
     $renderer->headLink()->appendStylesheet($basepath('css/select2.css'))->appendStylesheet($basepath('css/select2-bootstrap.css'));
     if ($scripts = $form->getOption('headscript')) {
         if (!is_array($scripts)) {
             $scripts = array($scripts);
         }
         foreach ($scripts as $script) {
             $headscript->appendFile($basepath($script));
         }
     }
     $class = $form->getAttribute('class');
     $class = preg_replace('~\\bform-[^ ]+\\b~', '', $class);
     $class .= ' ' . $layout;
     $form->setAttribute('class', $class);
     if (method_exists($form, 'prepare')) {
         $form->prepare();
     }
     $formContent = '';
     if ($form instanceof ViewPartialProviderInterface) {
         return $this->getView()->partial($form->getViewPartial(), array('element' => $form));
     }
     foreach ($form as $element) {
         $parameterPartial = $parameter;
         if (!$element->hasAttribute('id')) {
             $elementId = preg_replace(array('~[^A-Za-z0-9_-]~', '~--+~', '~^-|-$~'), array('-', '-', ''), $form->getName() . '-' . $element->getName());
             $element->setAttribute('id', $elementId);
         }
         if ($element instanceof ExplicitParameterProviderInterface) {
             $parameterPartial = array_merge($element->getParams(), $parameterPartial);
         }
         if ($element instanceof ViewPartialProviderInterface) {
             $parameterPartial = array_merge(array('element' => $element, 'layout' => $layout), $parameterPartial);
             $formContent .= $this->getView()->partial($element->getViewPartial(), $parameterPartial);
         } else {
             if ($element instanceof ViewHelperProviderInterface) {
                 $helper = $element->getViewHelper();
                 if (is_string($helper)) {
                     $helper = $this->getView()->plugin($helper);
                 }
                 $formContent .= $helper($element);
             } else {
                 if ($element instanceof FieldsetInterface) {
                     $formContent .= $this->getView()->formCollection($element, true, $layout);
                 } else {
                     $formContent .= $this->getView()->formRow($element, null, null, $layout);
                 }
             }
         }
     }
     return $this->openTag($form) . $formContent . $this->closeTag();
 }
开发者ID:bitrecruiter,项目名称:CrossApplicantManager,代码行数:64,代码来源:Form.php

示例6: setHorizontal

 /**
  * @param FormInterface|null $form
  */
 private function setHorizontal($form)
 {
     if ($this->isHorizontal && $form !== null) {
         if ($form->hasAttribute('class')) {
             $form->setAttribute('class', 'form-horizontal ' . $form->getAttribute('class'));
         } else {
             $form->setAttribute('class', 'form-horizontal');
         }
     }
 }
开发者ID:acplo,项目名称:acploui,代码行数:13,代码来源:Form.php

示例7: __invoke

 /**
  * Outputs message depending on flag
  *
  * @return string
  */
 public function __invoke(FormInterface $form, $class = 'form-horizontal')
 {
     $submitElements = [];
     $form->setAttribute('class', $class . ' well');
     $form->setAttribute('role', 'form');
     $form->prepare();
     $output = $this->getView()->form()->openTag($form);
     foreach ($form as $element) {
         if ($element instanceof Submit || $element instanceof Button) {
             $submitElements[] = $element;
         } elseif ($element instanceof Csrf || $element instanceof Hidden) {
             $output .= $this->getView()->formElement($element);
         } elseif ($element instanceof Collection) {
             $output .= $this->getView()->formCollection($element);
         } elseif ($element instanceof Checkbox) {
             // setup view model
             $viewModel = new ViewModel();
             $viewModel->setVariable('element', $element);
             $viewModel->setTemplate('zf2rapid-library/widget/bootstrap-form-checkbox');
             // render form element
             $output .= $this->getView()->render($viewModel);
         } else {
             $element->setAttributes(['class' => 'form-control']);
             $element->setLabelAttributes(['class' => 'col-sm-2 control-label']);
             // setup view model
             $viewModel = new ViewModel();
             $viewModel->setVariable('element', $element);
             $viewModel->setTemplate('zf2rapid-library/widget/bootstrap-form-group');
             // render form element
             $output .= $this->getView()->render($viewModel);
         }
     }
     // setup view model
     $viewModel = new ViewModel();
     $viewModel->setVariable('submitElements', $submitElements);
     $viewModel->setTemplate('zf2rapid-library/widget/bootstrap-form-submit');
     // render submit elements
     $output .= $this->getView()->render($viewModel);
     $output .= $this->getView()->form()->closeTag();
     return $output;
 }
开发者ID:zfrapid,项目名称:zf2rapid-library,代码行数:46,代码来源:BootstrapForm.php

示例8: setFormClass

 /**
  * Sets form layout class
  *
  * @param \Zend\Form\FormInterface $oForm
  * @param string $sFormLayout
  * @return void
  */
 protected function setFormClass(\Zend\Form\FormInterface $oForm, $sFormLayout = self::LAYOUT_HORIZONTAL)
 {
     if (is_string($sFormLayout)) {
         $sLayoutClass = 'form-' . $sFormLayout;
         if ($sFormClass = $oForm->getAttribute('class')) {
             if (!preg_match('/(\\s|^)' . preg_quote($sLayoutClass, '/') . '(\\s|$)/', $sFormClass)) {
                 $oForm->setAttribute('class', trim($sFormClass . ' ' . $sLayoutClass));
             }
         } else {
             $oForm->setAttribute('class', $sLayoutClass);
         }
     }
 }
开发者ID:Alfredao,项目名称:zf2-twb-bundle,代码行数:20,代码来源:TwbBundleForm.php

示例9: prepareElement

 /**
  * Prepare the form element (mostly used for rendering purposes)
  *
  * @param  FormInterface $form
  * @return mixed
  */
 public function prepareElement(FormInterface $form)
 {
     // Ensure the form is using correct enctype
     $form->setAttribute('enctype', 'multipart/form-data');
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:11,代码来源:File.php

示例10: openTag

 /**
  * Generate an opening form tag
  * @param  null|FormInterface $form
  * @param null|string $formType
  * @param array $displayOptions
  * @throws \DluTwBootstrap\Form\Exception\UnsupportedFormTypeException
  * @return string
  */
 public function openTag(FormInterface $form = null, $formType = null, $displayOptions = array())
 {
     $formType = $this->formUtil->filterFormType($formType);
     if (!array_key_exists($formType, $this->formTypeMap)) {
         throw new UnsupportedFormTypeException("Unsupported form type '{$formType}'.");
     }
     if ($form) {
         $class = $this->genUtil->addWords($this->formTypeMap[$formType], $form->getAttribute('class'));
         if (array_key_exists('class', $displayOptions)) {
             $class = $this->genUtil->addWords($displayOptions['class'], $class);
         }
         $escapeHtmlAttrHelper = $this->getEscapeHtmlAttrHelper();
         $class = $this->genUtil->escapeWords($class, $escapeHtmlAttrHelper);
         $form->setAttribute('class', $class);
     }
     return parent::openTag($form);
 }
开发者ID:gstearmit,项目名称:EshopVegeTable,代码行数:25,代码来源:FormTwb.php

示例11: renderBare

 /**
  * Render a form from the provided $form,
  *
  * @param FormInterface $form
  * @param string $layout
  * @param array $parameter
  * @return string
  */
 public function renderBare(FormInterface $form, $layout = self::LAYOUT_HORIZONTAL, $parameter = array())
 {
     /* @var $renderer \Zend\View\Renderer\PhpRenderer
      * @var $headscript \Zend\View\Helper\HeadScript
      * @var $basepath \Zend\View\Helper\BasePath */
     $renderer = $this->getView();
     $headscript = $renderer->plugin('headscript');
     $basepath = $renderer->plugin('basepath');
     $headscript->appendFile($basepath('Core/js/core.spinnerbutton.js'))->appendFile($basepath('js/select2.min.js'))->appendFile($basepath('Core/js/core.forms.js'));
     /* @noinspection PhpParamsInspection */
     $renderer->headLink()->appendStylesheet($basepath('css/select2.css'));
     if ($scripts = $form->getOption('headscript')) {
         if (!is_array($scripts)) {
             $scripts = array($scripts);
         }
         foreach ($scripts as $script) {
             $headscript->appendFile($basepath($script));
         }
     }
     $class = $form->getAttribute('class');
     $class = preg_replace('~\\bform-[^ ]+\\b~', '', $class);
     $class .= ' ' . $layout;
     $form->setAttribute('class', $class);
     $formId = $form->getAttribute('id') ?: $form->getName();
     $form->setAttribute('id', preg_replace(array('~[^A-Za-z0-9_-]~', '~--+~', '~^-|-$~'), array('-', '-', ''), $formId));
     if (method_exists($form, 'prepare')) {
         $form->prepare();
     }
     $formContent = '';
     if ($form instanceof ViewPartialProviderInterface) {
         return $renderer->partial($form->getViewPartial(), array('element' => $form));
     }
     /* @var $element \Zend\Form\ElementInterface */
     foreach ($form as $element) {
         $parameterPartial = $parameter;
         if (!$element->hasAttribute('id')) {
             $elementId = preg_replace(array('~[^A-Za-z0-9_-]~', '~--+~', '~^-|-$~'), array('-', '-', ''), $element->getName());
             $element->setAttribute('id', $elementId);
         }
         if ($element instanceof ExplicitParameterProviderInterface) {
             /* @var $element ExplicitParameterProviderInterface */
             $parameterPartial = array_merge($element->getParams(), $parameterPartial);
         }
         if ($element instanceof ViewPartialProviderInterface) {
             /* @var $element ViewPartialProviderInterface */
             $parameterPartial = array_merge(array('element' => $element, 'layout' => $layout), $parameterPartial);
             /** @noinspection PhpToStringImplementationInspection */
             $formContent .= $renderer->partial($element->getViewPartial(), $parameterPartial);
         } elseif ($element instanceof FieldsetInterface) {
             if ($element instanceof ViewHelperProviderInterface) {
                 /* @var $element ViewHelperProviderInterface */
                 $helper = $element->getViewHelper();
                 if (is_string($helper)) {
                     $helper = $renderer->plugin($helper);
                 }
                 $formContent .= $helper($element);
             } else {
                 $formContent .= $renderer->formCollection($element, true, $layout);
             }
         } elseif (false !== $element->getOption('use_formrow_helper')) {
             $formContent .= $renderer->formRow($element, null, null, $layout);
         } else {
             $formContent .= $renderer->formElement($element);
         }
     }
     return $this->openTag($form) . $formContent . $this->closeTag();
 }
开发者ID:cross-solution,项目名称:yawik,代码行数:75,代码来源:Form.php

示例12: bindForm

 protected function bindForm(FormInterface $form)
 {
     $form->setAttribute('type', 'create');
     $id = $this->getIdentifier();
     if ($id !== false) {
         $entity = $this->entityService->getEntityByIdentifier($id);
         if (!$entity) {
             //404
         }
         $form->setAttribute('type', 'edit');
     } else {
         $entityClass = $this->entityClass;
         $entity = new $entityClass();
     }
     $form->bind($entity);
     return $form;
 }
开发者ID:nobesnickr,项目名称:ApiTimesheets,代码行数:17,代码来源:FormController.php


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