I know how to create individual Zend_Form objects and display them in my view, 
error check them, etc.  Now what I am attempting to do though is have a form 
class that can be called via various methods and have different combinations of 
the form (output) be displayed.

If I only assign the first call of $form->assignToExisting() to my view, I get 
one form with one text field with the value of 'Test Field 1' as expected. If I 
have both calls though, I get two forms (as expected) but both have the same 
field of 'Test Field 2'. Am I not using clearElements() like I think it should 
be used?

Or is there a better way I should be approaching this?

Thanks!!


In my controller
----------------

$form = new forms_exception_assignPartnerAliases();

$this->view->form_assignToExisting       = $form->assignToExisting();
$this->view->form_createNew                 = $form->createNew();


Form Class
----------

class forms_exception_assignPartnerAliases extends Zend_Dojo_Form
{
                private $_request;

                // Normally a definition here - saving space in this post
                protected $_elementDecorators = null;

                public function init()
                {
                                // Get request object
                                $this->_request = 
Zend_Controller_Front::getInstance()->getRequest();

                                $this->setMethod( 'post' )
                                                ->setAction( 
'/manage/exception/assign/by/partner' )
                                                ->setName( 'assign' );
                }

                public function assignToExisting()
                {
                                // Clear all previous elements since this form 
object is being used to display two different forms via shared code base
                                $this->clearElements();

                                $this->_addHiddenElements();

                                $this->addElement(
                                                'text',
                                                'description',
                                                array(
                                                                'decorators'    
    => $this->_elementDecorators,
                                                                'label'         
           => 'Test Field 1',
                                                                'value'         
          => 'test1',
                                                )
                                );

                                return $this;
                }

                public function createNew()
                {
                                // Clear all previous elements since this form 
object is being used to display two different forms via shared code base
                                $this->clearElements();

                                $this->_addHiddenElements();

                                $this->addElement(
                                                'text',
                                                'description',
                                                array(
                                                                'decorators'    
    => $this->_elementDecorators,
                                                                'label'         
           => 'Test Field 2',
                                                                'value'         
          => 'test2',
                                                )
                                );

                                return $this;
                }

                private function _addHiddenElements()
                {
                                $this->addElement(
                                                'hidden',
                                                'qualifier',
                                                array(
                                                                'value'   => 
$this->_request->getParam('qualifier'),
                                                )
                                );
                }
}


----
Jeremy Brown, ZCE
Senior Web Developer
Spear One
972.661.6038
www.spearone.com<http://www.spearone.com>

Reply via email to