在多个页面上组织多个表单
我正在构建一个 Web 应用程序,其中包含大约 50 个表单。
我有一个非常好的表单构建类,可以很好地处理这些表单的创建和提交,并且它包含错误处理程序等。那里不需要帮助。
然而,这些表格分散在 120 页中。 我确实需要你们对这些页面/表单的理想组织结构进行一些权衡。 这里有一些想法。 两者都有优点和缺点。
每个页面在标题中创建表单,检测 $_POST['action'] 变量的存在并处理表单。
每个页面在标题中创建表单,检测 $_POST['action'] 变量的存在每个表单都由表单函数文件中的函数构建,并在页面标题中调用时返回表单对象,并且在处理时,由于 $_POST 是超全局函数,因此在页面标题中调用处理函数 函数
对于每个页面(例如 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.
Each page, in the header, creates the form there detects the presence of a $_POST['action'] variable and processes the forms there.
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.
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
选择3. - 以后维护代码会比一页一页地更改120页更容易。
Go for 3. - it will be easier to maintain the code later than to change 120 pages one by one.
斯库塔 我感谢你的帮助。 我最终使用了#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.