我在混合表单中嵌入了Mutt表单: MixForm.class.php:
$this->embedRelation('Mutt');
$form = new MuttForm(null, array(
'mix' =>$this->getObject(),
));
$this->embedForm('Mutt', $form);
$this->widgetSchema['Mutt'] = $form->getWidgetSchema();
$this->widgetSchema['Mutt']['mix_id'] = new sfWidgetFormInputHidden();
$this->validatorSchema['Mutt'] = $form->getValidatorSchema();
我需要为Mix表新创建的id表单填充Mutt表中的mix_id字段。
<?php echo $form->renderHiddenFields();?>
<?php echo $form['name']->renderRow();?>
<?php echo $form['parent1']->renderRow();?>
<?php echo $form['parent2']->renderRow();?>
<?php echo $form['parent3']->renderRow();?>
<?php echo $form['parent4']->renderRow();?>
<?php echo $form['parent5']->renderRow();?>
<?php echo $form['Mutt']['creator']->renderRow();?>
<?php echo $form['Mutt']['email']->renderRow();?>
<?php echo $form['Mutt']['website']->renderRow();?>
<?php echo $form['Mutt']['caption']->renderRow();?>
<?php echo $form['Mutt']['photo']->renderRow();?>
<?php echo $form['Mutt']['copyright']->renderRow();?>
<?php echo $form['Mutt']->renderHiddenFields();?>
这是我在modules / mix / actions / actions.class.php
中的行动public function executeEdit(sfWebRequest $request)
{
$this->form = new MixForm();
if($request->isMethod('post')):
$this->form->bind($request->getParameter('mix'), $request->getFiles($this->form->getName()));
if($this->form->isValid()):
$this->form->save();
$this->redirect('pure/add');
endif;
endif;
}
表单验证工作正常,但不会保存在任一数据库中。 我做错了什么?
答案 0 :(得分:0)
您正在为executeEdit
定义操作,但processForm
是表单验证并保存到数据库的操作。 executeEdit
是在编辑现有作业时显示表单的操作。
请参阅:http://www.symfony-project.org/jobeet/1_4/Doctrine/en/10#chapter_10_sub_the_form_action