简体   繁体   English

如何在Zend Framework 2中实现表单预览页面?

[英]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. 在我当前的ZF2项目中,我有一个复杂的Form有多层嵌套的Fieldset ,它反映了要在后台保存的对象的结构。 Currently the data is sent directly to the Controller and gets saved to the database, if it's valid. 目前,数据直接发送到Controller并保存到数据库(如果有效)。

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). 此页面/ action应该获取数据并以某种方式显示它(作为表格或者然而)。 The data needs to be stored somewhere temporarily and be ready to be "hydrated" to the Form object and saved. 数据需要暂时存储在某处,并准备好“水合”到Form对象并保存。 If the user wants to update the form, the form should be restored. 如果用户想要更新表单,则应该恢复表单。

How can I implement this requirement? 我该如何实现这个要求?

UPDATE 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). 预览应该是新页面,而不是同一页面上的JavScript /客户端生成的HTML(用于跟踪和其他目的)。

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. 我想说最好的解决方案是实现在执行表单POST请求之前执行的客户端(java-)脚本。 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. 如果用户单击“ accept ,则继续执行POST操作。 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 . 这个博客文章就是一个例子,但在Google的帮助下还有很多其他内容可以找到。

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

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

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