0

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

    $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');
4

1 回答 1

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));
于 2012-11-26T20:02:35.613 回答