简体   繁体   中英

How to implement a form preview page in Zend Framework 2?

In my current ZF2 project I have a complex Form with multiple levels of nested Fieldset s, that reflect the structure of objects to be saved in the background. Currently the data is sent directly to the Controller and gets saved to the database, if it's valid.

Now an intermediate step should be implemented: The user should get a chance to check the input data before it's saved to the database. If he decides, that it's correct, the form data should be submitted and saved to the database; if the user decides, that the form has to be edited, he should be able to go back to the form and correct it. (Of course all that in a loop, until the user is happy with the form and submit it.)

That means, a preview page is needed. This page/ action should get the data and display it somehow (as a table or however). The data needs to be stored somewhere temporarily and be ready to be "hydrated" to the Form object and saved. If the user wants to update the form, the form should be restored.

How can I implement this requirement?

UPDATE

I'm looking for a server-side solution. The preview should be a new page and not a JavScript/client-side generated HTML on the same page (for the tracking and other purposes).

I would say that the best solution would be to implement a client sided (java-)script that is executed before your perform the form POST request. You could catch the form submit event and render a client side view in which you show the current state of all the form fields (name and value). If the user clicks accept you continue the POST operation. If the user clicks cancel you return to the view of the form where you allow additional changes and the whole thing repeats itself.

It should not be difficult to find examples on how to do this...

One example is this blog post , but there are many more to find with the help of Google .

由于我不知道你的应用程序/ db是如何构造的,我只能推测你可以创建另一个表来保存临时数据,或者在用户提交表单后对其进行验证而不是将其保存到db使所有字段都读取 - 仅将原始提交按钮替换为将保存数据的按钮,以及将用户返回到他/她可以更改数据的表单的按钮。

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