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



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

我该怎么做
在调用新的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();
  }

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

$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

最新更新