gpt4 book ai didi

zend-framework2 - ZF2 : How to set form elements to be ignored?

转载 作者:行者123 更新时间:2023-12-04 07:08:42 25 4
gpt4 key购买 nike

不知何故,我无法忽略 Zend Framework 2 中的表单元素。

所有这些似乎都不起作用:

$this->add(array(
'name' => 'submit',
'ignore' => TRUE,
'attributes' => array(
'type' => 'submit',
'value' => 'Go!',
'id' => 'submitbutton',
'ignore' => TRUE
),
'options' => array(
'ignore' => TRUE
)
));

这是它过去在 Zend Framework1 中的工作方式:

//Zend Framework 1
$this->addElement(
'submit',
'login',
array(
'ignore' => true,
'label' => 'Login'
)
);

编辑:
为什么我需要“忽略”选项?

假设您的表单有一个提交按钮。使用普通的 PHP,类似 $_POST还将列出您的提交按钮。 Zend 1 具有有用的选项 setIgnore($flag)getIgnore()排除此类元素。 $form->getValues() (验证后)将排除所有带有标志 'ignore' 设置为 TRUE 的元素.见 ZF1 manual .

最佳答案

查看关于 inputfilters

我的用法是这样的:

  • 创建您的表单
  • 创建过滤器
  • 在 Controller 中使用
    $form = new BasicForm();
    $form->setInputFilter(new BasicFilter());

  • 关于过滤器,您可以这样做:
    $factory = new InputFactory();
        $this->add($factory->createInput(array(
    'name' => 'birthday',
    'required' => false,
    'allowEmpty' => true,));

    关于zend-framework2 - ZF2 : How to set form elements to be ignored?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15714627/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com