Search code examples
phpmysqldrupaldrupal-6

Drupal - Create a form


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?


Solution

  • 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.