2012-04-10 5 views
0

私の意見では、送信ボタンとキャンセルボタンがあるフォームがあります。両方のアクションが私をインデックスページに戻します。唯一の違いは、Submitは通常のdbサブミットを行い、「請求書が更新されました」というメッセージを表示するのに対して、Cancelは更新をキャンセルし、 'Update cancelled'を表示することです。ここでは、コントローラのコードは次のとおりです。CakePHPキャンセルボタンが起動しない

<fieldset> 
<legend>Enter New Values</legend> 
<li><?php echo $this->Form->input('purchaseOrderNumber'); ?></li> 
<li><?php echo $this->Form->input('siteAddress'); ?></li> 
<li><?php echo $this->Form->input('siteCity'); ?></li> 
<li><?php echo $this->Form->input('siteState'); ?></li> 
<?php 
echo $this->Form->button('Submit Form', array('type' => 'submit')); 
echo $this->Form->submit('Cancel', array('div' => false, 'name' => 'cancel')); 
?> 

しかし、ボタンが押されていない問題は、それは常に最初のメッセージを返します。

public function edit($id = null) { 
    $this->Invoice->id = $id; 
    $this->set('invoice', $this->Invoice->read(null, $id)); 
    //Check for $_GET 
    if ($this->request->is('get')) { 
     $this->request->data = $this->Invoice->read(); 
    } else { 
     // Bail if cancel button pressed 
     if (isset($this->params['form']['cancel'])) { 
      $this->Session->setFlash('Update canceled.'); 
      $this->redirect(array('action' => 'index')); 
     } else if ($this->Invoice->save($this->request->data)) { 
      $this->Session->setFlash('Your Invoice has been updated.'); 
      $this->redirect(array('action' => 'index')); 
     } else { 
      $this->Session->setFlash('Unable to update your Invoice.'); 
     } 
    } 
} 

そして、ここでは、ビューがあります。また、db submitも実行します。

NetbeansでXDebugを使用してみましたが、それは別の時間の話です。通常私の間違いは他人には明らかです。だから、誰かが私を軌道に乗せることを望んでいる。

+0

これをelse文の直後に置き、[キャンセル]をクリックすると、出力はどのようになりますか? 'デバッグ($ this-> params); exit; ' – Wylie

+0

リンクを使用してインデックスを作成しています –

答えて

1

私は同じ問題に取り組んでいましたが、単純にインデックスにリンクすることなく機能するソリューションを見つけました。 $this->paramsをデバッグするWylieの提案で、私は 'form'配列が作成されていないことに気付きました。しかし、 'cancel'パラメータが定義された 'data'という配列がありました。 だからあなたの代わりに

if (isset($this->params['form']['cancel'])) { 

使用

if (isset($this->params['data']['cancel'])) { 

の、どのボタンが押されたチェックされているコントローラで、あなたが作業を取得するためのボタンをキャンセル。

関連する問題