2010-06-04 19:18
浏览 29


I have a simple content edit form (Zend_Form) that I populate() with an array generated from the Zend_Db_Table_Row_Abstract->toArray() method. It works quite well.

The goal is to not populate one of the form elements with a value.

I'm currently solving this by removing that specific key => value pair from the populating array. I'm curious if there's a way to do that when generating the form element itself.


$foo = new Zend_Form_Element_Textarea('foo');

Any thoughts?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongtaihui5131 2010-06-05 01:57

    Nope. When you do $form->validate($data) or $form->populate($data) - internally this is simple

    foreach($formElements as $element) {

    theare no special internal flags like $form->_populationInProgress = true

    u can achive this easy by extending Zend_Form

    class App_Form extends Zend_Form
        protected $_ignoreDefaults = array();
        public function addIgnoredDefaultsElement(Zend_Form_Element $el)
            $this->_ignoreDefaults[$el->getName()] = true;
        public function isInIgnoregDefaults($name)
            return (bool)array_key_exists($name, $this->_ignoreDefaults);
        public function setDefault($name, $value) 
            if (!$this->isInIgnoregDefaults($name)) {
                parent::setDefault($name, $value);
            return $this;    
    打赏 评论

相关推荐 更多相似问题