简体   繁体   English

如何模拟Zend \\ Form提交而不在Zend Framework 2/3中显示表单?

[英]How to simulate a Zend\Form submit without to display the form in Zend Framework 2/3?

I have a complex nested (order) Zend\\Form , that can be edited multiple times. 我有一个复杂的嵌套(顺序) Zend\\Form ,可以多次编辑。 Now I want to get the data and pass it later to a new form. 现在,我想获取数据并将其稍后传递给新表单。 (This way I want to implement a simple cloning mechanism.) (通过这种方式,我想实现一个简单的克隆机制。)

What already works is transforming the request data to JSON 已经起作用的是将请求数据转换为JSON

if ($request->isPost()) {
    ...
    if(isset($request->getPost()->toArray()['store'])) {
        $this->storeFormJson(json_encode($request->getPost()));
    }
    ...
}
...

and passing it to an empty form: 并将其传递为空格式:

if ($this->params()->fromQuery('populate')) {
    $formDataJson = $this->getFormDataJson();
    $formDataArray = json_decode($formDataJson, true);
    $parameters = new Parameters($formDataArray);
    $request->setPost($parameters);
    $request->setMethod(Request::METHOD_POST);
}

Alright. 好的。 But it requires, that the user needs to call the edit form first, edit it (if needed), and send the data to the server (by submitting the form). 但这需要用户首先调用编辑表单,然后对其进行编辑(如果需要),然后将数据发送到服务器(通过提交表单)。 Since the goal is to create clones on the fly, I need a way to simulate these steps. 由于目标是即时创建克隆,因此我需要一种模拟这些步骤的方法。

How to get the data, that usually comes passed via form submitting, without a real submitting? 如何获取通常通过表单提交传递的数据而没有真正的提交?

One thought is to create a new form F2 in which the fields are all hidden, populate F2 with values from your populated form F1, deliver the rendered F2 form to the client, and add client-side javascript that auto-submits the now-populated F2 form on page load. 一种想法是创建一个新表单F2,其中所有字段都被隐藏,用填充的表单F1中的值填充F2,将呈现的F2表单传递给客户端,并添加客户端javascript,以自动提交现在填充的F2在页面上加载表格。 Just thinking out loud... 大声思考...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM