Reputation: 411
trying to create a form that has two submit buttons in cakephp.
task_1 submit button when clicked creates this in the address bar '/fields/add' and sends the information added to the database.
task_2 submit button when clicked creates this in the address bar '/fields/add/add' and sends the entered information to the database`.
task_1 is meant to allow users to keep creating new fields, where task 2 is meant to take them to a different page, at the moment we just chose a page at random.
here is the code for the add function in controller
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.');
}
}
}
here is the code for the add view
<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>
Upvotes: 0
Views: 4138
Reputation: 748
echo $this->Form->create('Field');
echo $this->Form->input('name');
echo $this->Form->input('description');
echo $this->Form->input('account_id');//this would be the conventional fk fieldname
echo $this->Form->button('Continue adding fields', array('name' => 'type_1'));
echo $this->Form->button('Finish adding fields', array('name' => 'type_2'));
echo $this->Form->end();
Upvotes: 2