1
在我的用戶控制器中,我有一個editAction。下面的聲明來自editAction。如何創建一個zend表單對象?
$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));
現在我需要通過電子郵件的形式類。但我不知道該怎麼做。 請在這方面幫助我。 謝謝
你是否在'forms/Admin/Users/Add.php'上創建了表單類?向我們顯示該代碼。 – Travesty3
是的,我做過。現在我已經附上了代碼 謝謝 – user1559230