Reputation: 2811
In my Users controller I have an editAction. The below declaration is from editAction.
$form = $this->_getEditForm();//here I need to pass $user->email to the form class.
I have another class _gerEditForm() in same controller.
private function _getEditForm()
{
$form = new Form_Admin_Users_Add(array(
'method' => 'post',
'action' => $this->_helper->url('edit', 'users'),
));
return $form;
}
enter code here
//form class
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));
Now I need to pass the email the form class. But I don't know how to do this. Please help me in this regard. Thanks
Upvotes: 1
Views: 113
Reputation: 14469
I'm a bit confused. The __construct
function takes one argument, $mail
. You're passing that to your BusinessForum_Validate_UniqueEmail
class.
But in your _getEditForm
function, you're passing in an array to that $mail
argument that looks like it has settings for the form, not email information.
If that's just how you named stuff, and that's how it works, fine. Then you should just need to add a second parameter to your __construct
function:
public function __construct($mail=null, $emailAddress="")
Pass it in from your _getEditForm
function:
private function _getEditForm($emailAddress="")
{
$form = new Form_Admin_Users_Add(array(
'method' => 'post',
'action' => $this->_helper->url('edit', 'users')
), $emailAddress);
return $form;
}
And pass the email address to your _getEditForm
function:
$form = $this->_getEditForm($user->email);
Upvotes: 1