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.
In controller I have
$request = $this->getRequest();
$request->setMethod('post')
->setPost(array(
'username' => 'admin',
'password' => '111111',
));
$this->dispatch(开发者_如何学C'/en/auth/login');
$values = $form->getValues();
I wonder how can I get values from this form? $form->getValues() will return a array? 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
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.
$values = $form->getValues();
$username = $values['login']['username'];
$password = $values['login']['password'];
精彩评论