在多个页面上组织多个表单

发布于 2024-07-12 06:26:04 字数 538 浏览 8 评论 0原文

我正在构建一个 Web 应用程序,其中包含大约 50 个表单。

我有一个非常好的表单构建类,可以很好地处理这些表单的创建和提交,并且它包含错误处理程序等。那里不需要帮助。

然而,这些表格分散在 120 页中。 我确实需要你们对这些页面/表单的理想组织结构进行一些权衡。 这里有一些想法。 两者都有优点和缺点。

  1. 每个页面在标题中创建表单,检测 $_POST['action'] 变量的存在并处理表单。

    每个页面在标题中创建表单,检测 $_POST['action'] 变量的存在
  2. 每个表单都由表单函数文件中的函数构建,并在页面标题中调用时返回表单对象,并且在处理时,由于 $_POST 是超全局函数,因此在页面标题中调用处理函数 函数

  3. 对于每个页面(例如 profile.php),在标头中包含一个包含 profile.forms.php 的文件,其中发生上述方法 #1 或 #2。

有想法吗?


请注意,每页很少会出现多个表格。

I have a web app I'm building that has about 50 forms.

I have a very nice form-building class that handles the creation and submission of these forms very nicely and it's wrapped with error handlers, etc. No help needed there.

However, the forms are scattered through 120 pages. I could really use some weigh in from you guys about the ideal organization structure for these pages/forms. Here are some ideas. Both have pros and cons.

  1. Each page, in the header, creates the form there detects the presence of a $_POST['action'] variable and processes the forms there.

  2. Each form is built by a function in a form functions file and returns the form object when it's called in the header of the page, and when processing, since $_POST is a superglobal the processing functions is called in the header of the page as well.

  3. For each page such as profile.php include a file in the header that includes a profile.forms.php in which the method #1 or #2 above happens.

Ideas?


Just a note, there will rarely be more than one form per page.

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

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

发布评论

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

评论(2

感性不性感 2024-07-19 06:26:04

选择3. - 以后维护代码会比一页一页地更改120页更容易。

Go for 3. - it will be easier to maintain the code later than to change 120 pages one by one.

虫児飞 2024-07-19 06:26:04

斯库塔 我感谢你的帮助。 我最终使用了#2,在充实了整个项目后,我对结果非常满意。 它的实施灵活且一致,我能够通过最少的培训轻松地将其他编码员引入该项目。

Skuta I appreciate your help. I ended up using #2 and after fleshing out the entire project I was extremely happy with the results. It was flexible and consistent in its implementation and I was able to easily bring on other coders to the project with a minimal amount of training.

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