dtwye28880 2015-01-07 23:35
浏览 205
已采纳

将HTML表单模板存储在数据库中

I am allowing users to create custom forms with any number of inputs and elements of their choosing. I then want the user to be able to save that form as a template of sorts so that other users could use that template to create their own custom form just like it.

There could be hundreds of different post types, each one with different elements etc.

What might be the best way to accomplish this in PHP and MySQL?

I am thinking of just storing the html of the custom form once a user has created it in the database. And so if another user wants to use that template, I'd just retrieve that html from the database and present it to the new user.

Is this the best way to do this? Many sites do similar things (Wufoo, for example), it just seems a little weird to me to store raw html like that in a database.

  • 写回答

2条回答 默认 最新

  • dongqiao8421 2015-01-07 23:41
    关注

    Anytime you're thinking of storing HTML in a database you're probably on the wrong lines.

    What if you want to make generalised structural changes to all forms? You'd suddenly have to go through all records and make that change.

    Instead, think in terms of using the DB only to store the bare bones of what's necessary to recreate the form later.

    Perhaps you'd have one DB table to store forms, another table with a one-to-many relationship to it that stores each field definition, and so on.

    So your DB would store the number of inputs, their type, labels, validation requirements - whatever. Then you'd have a big script that would rifle through these and - voila - rebuild the form.

    This approach:

    • gives you greater control of the general HTML structure
    • adheres more closely to the concept of normalising your DB data
    • adheres to the concept of keeping separate your data and structure (i.e. HTML)
    • cuts down the amount of data stored (no repeated tags, whitespace etc)
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答