Drupal - 创建表单
如何在 drupal 中创建一个包含大约 5 个文本字段的表单,允许用户输入数据,然后单击提交按钮并让它将所有数据保存到 mysql 数据库表中?
How do I create a form in drupal with about 5 text fields, allowing the user to enter in data, then click the submit button and get it to save all the data into a mysql database table?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我强烈邀请您阅读有关表单 API 的页面,它是 Drupal 管理表单的强大工具。
I strongly invite you to read this page about the form API, which is a powerful tool of Drupal to manage forms.
嗯,正如您从这个问题的其他回答中看到的,有很多不同的方法可以做到这一点。问题是,一旦数据进入 mysql,你想对它做什么。
1)如果你想将数据以某种方式存储在mysql中,并且数据将由某人审阅但通常不需要显示给用户,那么webform可能是最佳选择。它允许您轻松创建一个表单,人们可以在其中输入数据,然后特权用户可以在线或通过下载文件中的响应来查看结果。网络表单特别适合设置调查和其他表单,您只希望每个用户填写一次。
2)如果您希望人们回答表单中的问题,然后将结果作为数据显示在您的网站上,特别是如果您想在视图中显示结果,那么使用 cck 创建一个节点类型,并允许人们创建节点及其答案。确保每个用户创建一个节点一次有点棘手,但一旦创建它们就可以使用现有工具以多种不同的方式显示。
3) 如果您需要将表单输出放入您创建的或已提供给您的特定表中,那么最好认真学习 Form API 并自行构建代码。 Webform 和 CCK 创建供自己使用的表,如果您使用现有系统,则该表不起作用。
Well, as you can see from the other responses to this question, there's a lot of different ways to do this. The question becomes, what do you want to do with the data once it's in mysql.
1) If you want to have the data stored somehow in mysql, and the data is going to be reviewed by someone but doesn't need to be displayed to users in general, then webform is probably the way to go. It allows you to easily create a form which people can enter data into, and which a privileged user can then review the results either online or by downloading the responses in a file. Webform is particularly good for setting up surveys and other forms where you only want each user to fill it out once.
2) If you want people to answer the questions in the form, and then display the results as data on your website, and especially if you want to display the results in views, then creating a node type with cck, and allowing folks to create nodes with their answers. It's a little more tricky making sure each user creates a node once, but once they are created they can be displayed in a number of different ways with existing tools.
3) If you need the form output to go into a specific table that you've created or which has been given to you, then it's probably best to buckle down and learn the Form API and build the code yourself. Webform and CCK create tables for their own use which doesn't work if you're using an existing system.
您可以使用 Drupal Web 表单模块。
如果您想制作自定义表单,您可以创建自己的模块。
此链接将为您提供帮助。
http://drupallearn.blogspot.com/p/forms-in-drupal.html
You can use Drupal webform module.
If you want to make a custom form you can create your own module.
This link will help you.
http://drupallearn.blogspot.com/p/forms-in-drupal.html
您也可以尝试 webform 模块。它几乎可以满足您的需求
You may try the webform module also. It pretty much serves your need
如果您只需要几个字段,您可以使用 cck 模块并创建包含这些字段的内容,为所有创建内容的用户设置权限。
用views模块可以创建所有创建的列表。
cck
浏览量
if you just need a few fields you can use the cck module and create content that has these fields, set permissions for all users create the content.
With the views module can create a list of all creation.
cck
Views
尽管很多答案都建议使用 webform 模块,但编写自己的表单并不难,并且可以节省您安装不需要的 mkodule 的时间。 (数据库中更少的代码和更少的表是一件好事。)
要在 drupal 中创建一个包含大约 5 个文本字段的表单,允许用户输入数据,然后单击提交按钮并让它将所有数据保存到一个mysql 数据库表:
假设
mymodule
是你的模块的名称...Although a lot of the answers suggest using the webform module, coding your own forms is not hard and saves you installing a mkodule you don't need. (Less code and fewer tables in your DB is a good thing.)
To create a form in drupal with about 5 text fields, allowing the user to enter in data, then click the submit button and get it to save all the data into a mysql database table:
Assuming
mymodule
is the name of your module ...