I create my forms via extending Zend_Form. And I use one Form for addAction()
and editAction()
. When I want to remove Elements within the editing process I can do so easily via $form->removeElement('x')
.
But what would be the best approach on removing a field from the validator?
1) Removing and Adding the newly set validator
//Controllers editAction()
$form->removeValidator('Db_NoRecordExists');
$form->addValidator('Db_NoRecordExists', true, array(
'table'=>'table',
'field'=>'field',
'exclude'=>array(
'field'=>'id',
'value'=>$this->_getParam('id')
)
));
2) Injecting editing ID into the Form
//Forms Contstructor
public function __construct($idToEdit=0, $options=null)
{
$this->setIdToEdit($idToEdit);
parent::__construct($options);
}
//within init()
$formField->addValidator('Db_NoRecordExists', true, array(
'table'=>'table',
'field'=>'field',
'exclude'=>array(
'field'=>'id',
'value'=>$this->getIdToEdit()
)
));
//Controller calling the form like this:
$form = new Custom_Form($this->_getParam('id'), $options);
3) Something else? Maybe there is even something else I am missing, to me though somehow both ideas don't look too well to me.