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