我认为我有两种形式。但是当页面加载时,只有第二个表单显示值以进行编辑。如果第二个表单没有表中的任何值进行编辑,则第一个表单将保留值。我有一个resultsController,它从两个不同的组件表中读取值,并将这些值设置为视图中的表单。这两个表单具有单独的提交按钮,这些按钮在编辑后将值提交到相应的组件表。提交工作正常。我正在使用带有cakePhp 2.5.3的ajax提交。这两种形式都有独特的ID' Mtp01CompoAddForm'和' Mtp02CompoAddForm'。提交后,空白表格保留了价值。代码的相关部分如下:
Mtp01CompoAddForm:
echo $this->Form->create('Mtp01Compo', array('action' => 'add'));
echo $this->Form->input('id1',array('type'=>'hidden','value'=>$id1));
$options = array('0' => 'Low Activity ', '1' => 'Medium Activity' , '2' => 'High Activity','3' => 'Extreme Activity');
echo $this->Form->input('mtpResult_id', array('type' => 'hidden','value'=>$mtpResult_id));
echo $this->Form->input('q1',array('type'=>'radio','options'=>$options,'required'=>'required'));
echo $this->Form->input('q2',array('type'=>'radio','options'=>$options,'required'=>'required'));
echo $this->Form->submit('Submit', array('title' => 'Submit'));
$data = $this->Js->get('#Mtp01CompoAddForm')->serializeForm(array('isForm' => true, 'inline' => true));
$this->Js->get('#Mtp01CompoAddForm')->event(
'submit',
$this->Js->request(
array('controller'=>'Mtp01Compos','action' => 'add'),
array(
'method'=>'POST',
'data' => $data,
'async' => true,
'dataExpression'=>true,
)
)
);
echo $this->Form->end();
echo $this->Js->writeBuffer(array('inline' => 'true'));
echo $this->fetch('script');
?>
Mtp02CompoAddForm与不同数量的单选按钮类似,并提交给Mtp02Compos。 在我的控制器里,我有,
$this->Mtp01Compo->id=$id1;
$this->request->data = $this->Mtp01Compo->read();
$this->Mtp02Compo->id=$id2;
$this->request->data = $this->Mtp02Compo->read();
$this->set(array('mtpResult_id'=>$mtpResult_id));