简体   繁体   中英

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. 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

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. Just thinking out loud...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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