如何将ErrorDescription添加到Zend子表单元素?

时间:2012-11-26 19:33:26

标签: zend-framework zend-form

我有以下代码从表中生成子表单,我将错误描述保存在数据库中,我知道如何将其设置为普通元素但不是当它是子表单时,我该如何添加自定义每个子表单元素的错误消息?

    $subForm = new Zend_Form_SubForm();
    foreach($configuration as $config){

        $elements[] = array(
            new Zend_Form_Element_Text($config->configuration_key, array(
                'required'   => (($config->is_required == 1) ? true : false),
                'label'      => $config->configuration_title,
                'filters'    => array('StringTrim'),
                'value'     => $config->configuration_value,
                'Options'   => array('style'=>'width:90%;'),
                'Description' => $config->configuration_description,
                'errorMessage' => $config->errorMessage,

            ))
        );


    }
    $subForm->addElements($elements);
    $this->addSubForm($subForm, 'configuration');

1 个答案:

答案 0 :(得分:0)

在玩了很多不同的选项和试用/错误之后我发现我需要将'ErrorMessages'添加为数组,我重写了我的代码片段

        $elementSettings = array(
                'required'   => (($config->is_required == 1) ? true : false),
                'label'      => $config->configuration_title,
                'filters'    => array('StringTrim'),
                'value'     => $config->configuration_value,
                'Options'   => array('style'=>'width:90%;'),
                'Description' => $config->configuration_description,
                'ErrorMessages' => array($config->errorMessage)
            );
         $elements[] = array(new Zend_Form_Element_Text($config->configuration_key, $elementSettings));