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


PHP Form\FormInterface类代码示例

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


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

示例1: openTag

 /**
  * Generate an opening form tag
  *
  * @param  null|FormInterface $form
  * @return string
  */
 public function openTag(FormInterface $form = null)
 {
     $attributes = array('action' => '', 'method' => 'get');
     if ($form instanceof FormInterface) {
         $formAttributes = $form->getAttributes();
         if (array_key_exists('class', $formAttributes) && !empty($formAttributes['class'])) {
             $formAttributes['class'] = $formAttributes['class'] . ' ';
         } else {
             $formAttributes['class'] = '';
         }
         switch ($form->getFormLayout()) {
             case FormInstance::FORM_LAYOUT_SEARCH:
                 $formAttributes['class'] .= 'form-search';
                 break;
             case FormInstance::FORM_LAYOUT_INLINE:
                 $formAttributes['class'] .= 'form-inline';
                 break;
             case FormInstance::FORM_LAYOUT_HORIZONTAL:
             default:
                 $formAttributes['class'] .= 'form-horizontal';
                 break;
         }
         if (!array_key_exists('id', $formAttributes) && array_key_exists('name', $formAttributes)) {
             $formAttributes['id'] = $formAttributes['name'];
         }
         $attributes = array_merge($attributes, $formAttributes);
     }
     $tag = sprintf('<form %s>', $this->createAttributesString($attributes));
     return $tag;
 }
开发者ID:rumeau,项目名称:zf-twitter-bootstrap,代码行数:36,代码来源:Form.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: renderAdditional

 public function renderAdditional(FormInterface $form, $type)
 {
     $result = '';
     foreach ($this->contactTypes[$type] as $fieldName => $fieldOptions) {
         $result .= $this->renderElement($form->get($fieldName), $fieldOptions, true);
     }
     return $result;
 }
开发者ID:zource,项目名称:zource,代码行数:8,代码来源:ContactForm.php

示例4: validate

 public function validate(FormInterface $form, array $data)
 {
     $argv = compact('form', 'data');
     $this->getEventManager()->trigger(__METHOD__ . '.pre', $this, $argv);
     $form->setData($data);
     $isValid = $form->isValid();
     $this->getEventManager()->trigger(__METHOD__ . '.post', $this, $argv + array('success' => $isValid));
     return $isValid;
 }
开发者ID:juic3pow3rs,项目名称:LdcUserProfile,代码行数:9,代码来源:ProfileService.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: render

 /**
  * @param string $content
  * @param array $attribs
  * @param ElementInterface $element
  * @param FormInterface $form
  * @return string
  */
 public function render($content, array $attribs = [], ElementInterface $element = null, FormInterface $form = null)
 {
     if ($form && $form->hasAttribute('class')) {
         $class = $form->getAttribute('class');
         if (strpos($class, 'form-inline') !== false) {
             return $content;
         }
     }
     return parent::render($content, $attribs);
 }
开发者ID:coolms,项目名称:twbs,代码行数:17,代码来源:FormGroupRow.php

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

示例8: handle

 public function handle(FormInterface $form, $options = array())
 {
     $options = array_merge($form->getOptions(), $options);
     if (!isset($options[self::PARSED_FORM_OPTION_KEY])) {
         $options[self::PARSED_FORM_OPTION_KEY] = new \FzyForm\Annotation\Form($form, $this->getServiceLocator()->get('FzyCommon\\Service\\EntityToForm'));
         $form->setOptions($options);
     }
     /* @var $annotated \FzyForm\Annotation\Form */
     $annotated = $options[self::PARSED_FORM_OPTION_KEY];
     return $this->getServiceLocator()->get('FzyCommon\\Render')->handle($annotated->getTemplate(), array('element' => $annotated, 'options' => $options));
 }
开发者ID:fousheezy,项目名称:form,代码行数:11,代码来源:Render.php

示例9: openTag

 /**
  * Generate an opening form tag
  *
  * @param  null|FormInterface $form
  * @return string
  */
 public function openTag(FormInterface $form = null)
 {
     $attributes = array('action' => '', 'method' => 'get');
     if ($form instanceof FormInterface) {
         $formAttributes = $form->getAttributes();
         if (!array_key_exists('id', $formAttributes) && array_key_exists('name', $formAttributes)) {
             $formAttributes['id'] = $formAttributes['name'];
         }
         $attributes = array_merge($attributes, $formAttributes);
     }
     return sprintf('<form %s>', $this->createAttributesString($attributes));
 }
开发者ID:tillk,项目名称:vufind,代码行数:18,代码来源:Form.php

示例10: setFormClass

 /**
  * Sets form layout class
  *
  * @param FormInterface $oForm
  * @param string $sFormLayout
  * @return void
  */
 protected function setFormClass(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:nebunel,项目名称:zf2-twb-bundle,代码行数:20,代码来源:TwbBundleForm.php

示例11: editPageRepository

 public function editPageRepository(FormInterface $form)
 {
     $page = $form->getObject();
     if (!$form->isValid()) {
         throw new RuntimeException(print_r($form->getMessages(), true));
     }
     $data = $form->getData(FormInterface::VALUES_AS_ARRAY);
     $formClone = clone $form;
     $formClone->bind($page);
     $formClone->setData($data);
     $formClone->isValid();
     $this->assertGranted('page.update', $page);
     $this->getObjectManager()->persist($page);
     return $page;
 }
开发者ID:andreas-serlo,项目名称:athene2,代码行数:15,代码来源:PageManager.php

示例12: updateAction

 public function updateAction()
 {
     $request = $this->getRequest();
     $recipe = $this->readService->findById($this->params('id'));
     if (false === $this->authorizationService->isGranted('recipe.manage', $recipe)) {
         throw new UnauthorizedException('Insufficient Permissions');
     }
     $viewModel = new ViewModel();
     $viewModel->setTemplate('recipe/update');
     $viewModel->setVariables(['form' => $this->form]);
     $this->form->bind($recipe);
     if ($request->isPost()) {
         $this->form->setData($request->getPost());
         if ($this->form->isValid()) {
             try {
                 $this->writeService->save($this->form->getData());
                 $this->flashMessenger()->addSuccessMessage('Rezept erfolgreich aktualisiert');
                 $this->redirect()->toRoute('recipe/read/update', ['id' => $this->params('id')]);
             } catch (\Exception $e) {
                 var_dump($e->getMessage());
             }
         }
     }
     $this->layout('layout/backend');
     return $viewModel;
 }
开发者ID:Indigo1337,项目名称:c4d,代码行数:26,代码来源:Update.php

示例13: indexAction

 public function indexAction()
 {
     $request = $this->getRequest();
     $logContent = '';
     // initialize when no submit anymore
     $data = [];
     $data['logmessage'] = $this->form->get('logmessage')->getValue();
     if ($request->isPost()) {
         $this->form->setData($request->getPost());
         if ($this->form->isValid()) {
             $data = $this->form->getData();
             $this->loggerPriority = $data['logpriority'];
             if ($data['logformat'] !== 'simple') {
                 $this->loggerConfig['writers'][0]['options']['formatter']['name'] = $data['logformat'];
                 unset($this->loggerConfig['writers'][0]['options']['formatter']['options']);
             }
         }
     }
     $logger = new Logger($this->loggerConfig);
     // save log data to buffer and make it variable
     ob_start();
     $logger->log((int) $this->loggerPriority, $data['logmessage']);
     $logContent = ob_get_clean();
     return new ViewModel(['form' => $this->form, 'logContent' => $logContent]);
 }
开发者ID:shitikovkirill,项目名称:LearnZF2,代码行数:25,代码来源:IndexController.php

示例14: createAction

 public function createAction()
 {
     if ($this->getRequest()->isPost()) {
         $this->dashboardForm->setData($this->getRequest()->getPost());
         if ($this->dashboardForm->isValid()) {
             $data = $this->dashboardForm->getData();
             $this->dashboardTaskService->persistFromArray($data);
             return $this->redirect()->toRoute('dashboard/manage');
         }
     }
     return new ViewModel(['dashboardForm' => $this->dashboardForm]);
 }
开发者ID:zource,项目名称:zource,代码行数:12,代码来源:Dashboard.php

示例15: indexAction

 /**
  * 
  * @return ViewModel|Response
  */
 public function indexAction()
 {
     if (!is_null($this->identity())) {
         return $this->redirect()->toRoute($this->loginRedirectRoute);
     }
     if ($this->getRequest()->isPost()) {
         $this->loginForm->setData($this->getRequest()->getPost());
         if ($this->loginForm->isValid()) {
             return $this->redirect()->toRoute($this->loginRedirectRoute);
         }
     }
     return new ViewModel(array('loginForm' => $this->loginForm));
 }
开发者ID:ughly,项目名称:ugh-authentication,代码行数:17,代码来源:LoginController.php


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