0

// 查看代码

echo $form->Create('Survey'); 

echo $form->submit( 'prev.arrow.png', array( 'name' => 'task', 'value' => 'next', 'div' => false ) ); 

echo $form->submit( 'next.arrow.png', array( 'name' => 'task', 'value' => 'prev', 'div' => false ) ); 

echo $form->end();

// 控制器代码

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

    if( $this->params['form']['task'] == 'prev' ) {

        $this->Redirect( $prev_page ); 

        exit(); 

    } else if ( $this->params['form']['task'] == 'next' ) {

        $this->Redirect( $next_page ); exit(); 

    }

}

// 这没用 !!!而且我还有超过 7 个提交按钮。和一个处理数据库中保存逻辑记录的最终按钮。如果还有其他逻辑……还建议吗?

4

1 回答 1

0

您的表单正在提交 2 个具有相同名称的变量。(任务)如果不介意您按下哪个按钮,您总是提交inputs表单标签(<form></form>)之间包含的所有内容因此,您正在覆盖其中一个。

我建议您根据单击的按钮在控制器中调用两个不同的操作。

为此,您可以使用postLinkForm helper 的操作创建两个按钮,而不是创建带有两个按钮的表单。

就像是:

//calling the `prev` action for the current controller
echo $this->Form->postLink("Prev", array('action'=> 'prev'), array( 'class' => 'button'));

//calling the `next` action for the current controller
echo $this->Form->postLink("Next", array('action'=> 'next'), array( 'class' => 'button'));

然后在你的控制器中:

public function prev(){
   .... //whatever
}

public function next(){
   ... //whatever
}

或者,您也可以创建 2 个具有两种不同提交操作的表单,每个按钮一个。但它会是一样的。

于 2013-03-04T11:25:30.643 回答