试图在 cakephp 中创建一个有两个提交按钮的表单。
单击任务_1 提交按钮时,会在地址栏“/fields/add”中创建此按钮,并将添加的信息发送到数据库。
单击 task_2 提交按钮时,会在地址栏“/fields/add/add”中创建此按钮,并将输入的信息发送到数据库。
task_1 旨在允许用户不断创建新字段,其中任务 2 旨在将他们带到不同的页面,目前我们只是随机选择一个页面。
这是控制器中添加功能的代码
function add(){
$this->set('title_for_layout', 'Please Enter Your Invoice Headings');
$this->set('stylesheet_used', 'style');
$this->set('image_used', 'eBOXLogo.jpg');
$this->Session->setFlash("Please create your required fields.");
if($this->request->is('post')){
$this->Field->create();
if ($this->Field->save($this->request->data))
{
if($this->params['form']['task_1'] == "task_1")
{
$this->Session->setFlash('The field has been saved');
$this->redirect( array('controller' => 'Fields','action' => 'add'));
}
if($this->params['form']['task_2'] == "task_2")
{
$this->Session->setFlash('The template has been saved');
$this->redirect( array('controller' => 'Invoices','action' => 'add'));
}
}
else
{
$this->Session->setFlash('The field could not be saved. Please, try again.');
}
}
}
这是添加视图的代码
<form enctype="multipart/form-data" method="post" action="add/">
Name: <input type ="text" name="name" /> <br />
Description: <input type ="text" name="description" /> <br />
Account ID: <input type ="number" name="accounts_id" /> <br />
<br />
<input type="submit" name="task_1" value="Continue adding fields" />
<input type="submit" name="task_2" value="Finish adding fields" />
</form>