使用“保存和新文档”按钮提交表单

时间:2012-09-04 15:35:42

标签: atk4

我使用一个简单的表单来提交一些新的文档信息,并希望用户能够点击“保存和新文档”按钮,这样他就可以轻松添加多个文档。 我试图在表单中添加一个按钮,第一次点击“保存和新建”按钮,然后在现有按钮上弹出另一个表单,但之后按钮停止工作。 可能是因为我没有正确关闭前一个,当产生新的?

我该怎么做? 我在调用新的dialogURL()之前尝试使用closeDialog()但显然不起作用......

(简化)代码示例如下:

class page_informa_documento extends Page {

  function init(){
  parent::init();
  $f=$this->add('Form');
  $f->setModel('Document');
  $f->addSubmit('Save');
  $f->addButton('Save and new document')->js('click',$f->js()->atk4_form('submitForm','otro'));


  if($f->isSubmitted() )
  {
      // save document info we just got here
      $doc->save();

    if ($f->isClicked('otro')) 

      $f->js()->univ()->dialogURL('New Document',$this->api->getDestinationURL('/informa/documento'))->execute();

    else  $f->js()->univ()->closeDialog()->execute();
  }

1 个答案:

答案 0 :(得分:0)

如果您需要表单数据,则必须添加多个“提交”按钮。

$a=$f->addSubmit('Save');
$b=$f->addSubmit('Save and Add More');
if($f->isSubmitted()){

    // save your document here

    if($f->isClicked($a)){
        $this->js()->univ()->location($this->api->url('index'))->execute();
        // go to index page, we are done
    }
    if($f->isClicked($b)){
        $this->js()->univ()->location($this->api->url()->execute();
        // stay on the same page, just reload
    }
}

以下是演示:http://test-suite.agiletoolkit.org/?page=form

来源取自此处:https://github.com/atk4/atk4-testsuite/blob/master/page/form.php#L16