embedForm额外字段隐藏

时间:2012-07-12 10:25:15

标签: symfony1 symfony-1.4 symfony-forms

我在listForm.class.php中的部分代码:

public function configure() {
    $list_id = $this->getOption('list_id');
    $endkunde_id = $this->getOption('endkunde_id');
    $shopname_id = 1;


    $todoWrapperForm = new sfForm();
    $todoWrapperForm = new sfForm();
    //$todos = Doctrine_Core::getTable('Todo')->findAll();


    //$todos = Doctrine_Core::getTable('EinkaufslisteElemente')->findAll();
    $todos = Doctrine_Core::getTable('EinkaufslisteElemente')
            ->createQuery('ee')
            ->where('ee.einkaufsliste_id = ?', $list_id)
            ->innerJoin('ee.Einkaufsliste e')

            ->andWhere('e.shopname_id = ?', $shopname_id)
           ->innerJoin('e.EinkaufslisteEndkunde ek')
            ->execute();


    foreach ($todos as $todo) {
        $todoWrapperForm->embedForm($todo->getId(), new EinkaufslisteElementeForm($todo));
    }
    $todoWrapperForm->embedForm('new_1', new EinkaufslisteElementeForm());  // add one blank todo to start
    $this->embedForm('todos', $todoWrapperForm);


        $this->list =  new sfWidgetFormTextarea(array(), array('rows' => '10', 'cols' => '35'));

    $this->mergePostValidator(new sfValidatorDoctrineUnique(array('model'=>'todo', 'column'=>'task'), array('required' => false)))               ;
    $this->widgetSchema->setNameFormat('todo_list[%s]');
}

我想从'Customer'创建一个额外字段,其名称未隐藏,我想创建一个隐藏在表'List'中的list_id的输入字段。我怎么能用embedForm来做呢?

1 个答案:

答案 0 :(得分:2)

listForm内,只需在配置的底部添加:

$this->widgetSchema['list_id']    = new sfWidgetFormInputHidden();
// do not forget to add the propel validator (ie: the one that can check if `list_id` is ok - like in the database)
$this->validatorSchema['list_id'] = new sfValidatorPass();

然后,在您的操作中,不要忘记将默认值设置为list_id

$form = new listForm();
$form->setDefault('list_id', $list_id);
相关问题