0

Cakephp で送信ボタンが 2 つあるフォームを作成しようとしています。

task_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> 
4

1 に答える 1

2
    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();
于 2012-07-31T09:14:21.073 に答える