在我的用户控制器中,我有一个 editAction。以下声明来自editAction。
$form = $this->_getEditForm();//here I need to pass $user->email to the form class.
我在同一个控制器中有另一个类 _gerEditForm() 。
private function _getEditForm()
{
$form = new Form_Admin_Users_Add(array(
'method' => 'post',
'action' => $this->_helper->url('edit', 'users'),
));
return $form;
}
enter code here
//表单类
class Form_Admin_Users_Add extends Form_Abstract
{
public function __construct($mail=null)
{
parent::__construct();
$this->setName('user');
//$userId = new Zend_Form_Element_Text('userId');
//$userId->addFilter('Int');
//$this->addElement($userId);
$this->setAttrib('id', 'addUserForm');
$this->setAttrib('class', 'formInline');
$firstName = new Zend_Form_Element_Text('firstName');
$firstName->setRequired(true)
->addFilter('StringTrim')
->addValidator('NotEmpty', false, array('messages'=>'First name cannot be empty'))
->addValidator('StringLength', false, array(1, 256))
->setLabel('First Name:');
$this->addElement($firstName);
$lastName = new Zend_Form_Element_Text('lastName');
$lastName->setRequired(true)
->addFilter('StringTrim')
->addValidator('NotEmpty', false, array('messages'=>'Last name cannot be empty'))
->addValidator('StringLength', false, array(1, 256))
->setLabel('Last Name:');
$this->addElement($lastName);
$email = new Zend_Form_Element_Text('email');
$email->setLabel('Email :')
->addValidator('NotEmpty', false, array('messages'=>'email cannot be empty'))
->addFilter('StripTags')
->addFilter('StringTrim')
->addValidator('EmailAddress')
->addValidator(new BusinessForum_Validate_UniqueEmail($mail));
现在我需要将电子邮件传递给表单类。但我不知道该怎么做。请在这方面帮助我。谢谢