Zend_Form:非标准表单的新手。我还应该使用 Zend_Form 吗?

发布于 2025-01-05 04:27:23 字数 867 浏览 3 评论 0原文

<强>!!!已更新!!!

我们有来自多个来源(内部、客户、供应商)的复杂产品数据电子表格。
由于作者身份如此多样化,因此尝试管理格式细节(例如列顺序和标题行数)是不切实际的。

这些 CSV 电子表格将通过现有表单上传到我们的数据库。
(我的第一个 Zend_Form ...我快完成了)

用户需要查看给定电子表格中的示例,以便他们可以映射列和起始行。
为了实现这一点,我需要生成该动态内容的 html 表,并将表单元素编织在表数据中和周围。
用户将选择要在每列中找到哪些值,并标识第一行数据(在任何标题行之后)。
点击此处查看示例。
(注意:我在这里的大部分工作都是在保密协议下进行的,所以人为的例子是我们能得到的最好的:)
在此示例中,我期望输出为:

_POST('first_row'=>2, 'column0'=>'mi', 'column1'=>'lName', 'column2'=>'fName', 'column3'=>'gender')

映射/定义所有这些规范后,可以解析上传的电子表格,并将准确的数据添加到 Product_history 数据库中。

ZF 是解决这个特定问题的好工具吗?还是我应该从头开始写一些东西?
会如何解决这个问题?
我终于刚刚开始在我的脑海中直接了解这些采埃孚的东西,而这个让我完全迷失了:)

任何和所有的建议表示赞赏。
~莫

!!! UPDATED !!!

We have spreadsheets of complex product data coming in from multiple sources (internal, customers, vendors).
Since the authorship is so diverse, it's impractical to try governing formatting details such as column order and the number of header-rows.

These CSV spreadsheets will be uploaded to our DB via an existing form.
(My first Zend_Form ... I'm almost done with it)

The user needs to see a sample from a given spreadsheet so they can Map the columns and start-row.
To achieve that, I need to generate an html table of that dynamic content, and weave the form elements in and around the table data.
The user would select which values are to be found in each column, and identify the first row of data (after any header rows).
CLICK HERE to see an example.
(NOTE: Most of my work here is under an NDA, so contrived examples is the best we can get :)
In this example, I'd expect the output to be:

_POST('first_row'=>2, 'column0'=>'mi', 'column1'=>'lName', 'column2'=>'fName', 'column3'=>'gender')

With all those scpecifics mapped/defined, the uploaded spreadsheet can then be parsed and accurate data can be added to the product_history database.

Is ZF a good tool for this particular problem, or should I just write something from scratch?
How would you aproach this?
I am finally JUST BARELY starting to get this ZF stuff straight in my head, and this one has got me totally lost :)

Any and All advice appreciated.
~ Mo

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

羁拥 2025-01-12 04:27:23

我认为在你的情况下,使用 Zend_Form 对这种情况会有帮助。

当然,棘手的部分是您的表单将在很大程度上根据 CSV 文件的标题和第一行内容动态动态生成。

无论您使用 Zend_Form、纯 PHP 还是其他解决方案,您要做的很多事情都是相同的(分析 CSV、基于 CSV 提供动态输入,然后对选择进行错误检查)。我认为使用 Zend_Form 的优点是可以非常干净地制作这样的东西。

鉴于 Zend_Form 的性质,例如它如何根据添加到 Zend_Form 本身的元素来验证现有表单,您需要对表单采取特殊的方法。基本上,用户上传 CSV 一次后,您将根据列数、它们在 CSV 中的位置以及列的名称创建一个 Zend_Form 对象。

由于您不想打扰用户在做出错误选择时多次上传 CSV,因此我会将 CSV 解析为某种结构,可能是一个简单的对象或数组,然后基于该数据构建您的 Zend_Form。这样,您可以将该结构保存到会话中,这样您就可以继续根据解析的数据重新生成表单,而不必每次都读取文件。这是因为 Zend_Form 和动态表单的主要挑战是,当您想要显示表单时,表单不仅需要所有元素及其属性,而且还需要它们来验证表单并重新显示经验证的表格。

我记得很多年前在 PHP 脚本中看到过这个功能,我发现它仍然可用。也许你可以看看它来寻找想法。我不会在这里发布链接,因为屏幕截图和脚本大多与成人网站相关,并且该网站大部分是 NSFW,但它被 JMBSoft 称为 TGPX。主产品页面上的第八个屏幕截图中的第七个显示了导入过程,它允许用户将字段映射到数据,这正是您正在做的事情。

希望我的建议对你有帮助,有任何问题欢迎评论。

I think in your case, using Zend_Form would be helpful for this situation.

The tricky part to it is of course that your forms are going to be largely dynamically generated on-the-fly based on the header and first row content of the CSV file.

Whether you used Zend_Form, or pure PHP, or some other solution, a lot of what you will be doing is the same (analyzing the CSV, providing dynamic inputs based on the CSV, and then error checking the selections). I think using Zend_Form has the advantage of making something like this very cleanly.

Given Zend_Form's nature, e.g. how it validates existing forms based on the elements added to the Zend_Form itself, you need to take a special approach with the form. Basically, after the user uploads the CSV once, you will create a Zend_Form object based on the number of columns, their positions in the CSV, and the name of the column.

Since you don't want to bother the user to upload the CSV multiple times if they make incorrect selections, I would parse the CSV into some sort of structure, maybe a simple object or array, and then build your Zend_Form based on that data. This way, you can save that structure to the session, so you can continue to regenerate the form based on the parsed data without having to read the file each time. This is because the main challenge with Zend_Form and dynamic forms, is that not only does the form need all of the elements and their properties when you want to display the form, but they are also required in order to validate the form and re-display the validated form.

I remember seeing this functionality many years ago in a PHP script, which I found is still available. Perhaps you could look at it for ideas. I won't post the link here since the screenshots and script are mostly adult website related and the site is NSFW for the most part, but it is called TGPX by JMBSoft. The 7th of the 8th screenshot on the main product page shows the import process where it lets the user map fields to data, exactly what you are doing.

Hope my advice is helpful, feel free to comment with any questions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文