如何在社交引擎中的控制器中添加表单元素

时间:2016-10-18 10:39:55

标签: php frameworks socialengine

class Module_PhotoController extends Core_Controller_Action_Standard
{   
    public function nameAction()
    {                           
        $this->view->form = $form = new Modulename_Form_Fromname();
        $this->addElement('Text', 'sender', array(
            'label' => 'Send to',
            'maxlength' => '40',
            'filters' => array(
                //new Engine_Filter_HtmlSpecialChars(),
                'StripTags',
                new Engine_Filter_Censor(),
                new Engine_Filter_StringLength(array('max' => '63')),
            )
        ));
    }
}  

2 个答案:

答案 0 :(得分:3)

试试此代码

$form->addElement('Text', 'sender', array(
            'label' => 'Send to',
            'maxlength' => '40',
            'filters' => array(
                    //new Engine_Filter_HtmlSpecialChars(),
                    'StripTags',
                    new Engine_Filter_Censor(),
                    new Engine_Filter_StringLength(array('max' => '63')),
            )
    ));

答案 1 :(得分:1)

执行此操作的正确方法是编辑/application/modules/Modulename/Form/Fromname.php中的文件并使用addElement向表单添加特定元素。在控制器中构造表单并不是最好的SE编程实践。