dongyi5570 2010-06-04 19:18
浏览 29
已采纳

如何填充()整个Zend_Form减去一个表单元素?

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.

Say...

$foo = new Zend_Form_Element_Textarea('foo');
$foo->ignoreDefaultValue(true);
$form->addElement($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) {
        $element->setDefault($newValue);
    }
    

    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;    
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动