简体   繁体   English

如何在 zend 项目中获取 Zend_Form 的值

[英]How can I get the value of a Zend_Form in zend project

I have a Zend_Form called login.php in my zend project.我的 Zend 项目中有一个名为 login.php 的 Zend_Form。

In controller I have在 controller 我有

$request = $this->getRequest();
        $request->setMethod('post')
                ->setPost(array(
                    'username' => 'admin',
                    'password' => '111111',
                ));
        $this->dispatch('/en/auth/login');
        $values = $form->getValues();

I wonder how can I get values from this form?我想知道如何从这个表单中获取值? $form->getValues() will return a array? $form->getValues() 会返回一个数组吗? and how to get the username and password form it?以及如何获取用户名和密码表呢?

if($this->getRequest()->isPost())
{
   if($form->isValid($this->getRequest()->getPost())
   {
      //Here is form->getValue() enabled
      echo $form->getValue('elementName');
   }
}

getValue isn't available unti the form is valid getValue 在表单有效之前不可用

another option:另外的选择:

$values = $form->getValues();

$username = $values['username'];
$password = $values['password'];

and if are using:如果正在使用:

$form->setElementBelongsTo(´login');

then you need to call the ElementBelongsTo string first.那么您需要先调用 ElementBelongsTo 字符串。

$values = $form->getValues();

$username = $values['login']['username'];
$password = $values['login']['password'];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM