Update : this article is only relevant to Drupal 5.x, with coming of Drupal 7 this is completely out dated.
I am guessing you must have created lot’s of html forms before, now you have started using Drupal and wondering how to create forms in Drupal and process them. If this is so then read on….
What is Drupal Form API?
Drupal form api, is nothing but a set of functions(off-course, that’s what api means) provided by Drupal as part of core functionality, since version 4.7, for us Drupal developers to create, validate and process our html forms, in a secure manner. When i say secure, i mean that you form data is almost free from injection attacks, but you do need to validate this data as per your own application requirements.
It essentially means we will be creating arrays with relevant data and Drupal’s form generation engine will generate the html form for us.
Ok, so what?
I can create my own forms using html, why should i care about Drupal’s form api?
Simple, if you want to extend the forms provided by other Drupal modules or Drupal itself(which you will have too, most of the time), with out actually modifying their code, then use Drupal’s form api.
See if we want to use the benefits of modularity Drupal provides we should be able to modify the forms created by others to suit our needs.
Well you must be wondering, this can be done by editing the code provided by the module. Sure you can do that, but in the process you loose the ability to upgrade that module when a new version comes along, because upgrading means porting all those changes again, now you are stuck.
On the other hand if you have your own module, using form api, then all you need to it is just modify in you source files, while you can simple upgrade the module without worrying about loosing your changes.
This also means you can split you form in many usable components and the piece them together for end user. This will give you reusability benefits that we programmers strive for.
Not yet convinced…
Let me see what i can do about that.. Ok let’s try this line of thought, when you used to create html forms of similar types, one after other from one project to other did you ever thought their should be a form generator, where you specify the parameter and it automatically generates the form for you. If yes then, consider your wish granted as Drupal’s Form API is one such thing that makes form creation an easy task.
Ok, now i am assuming that you understood the importance of form api, then next thing to do is to understand how Drupal process the forms. When you understand the flow, you can control it. So let’s get on to it.
Drupal Form process flow



