Drupal 7 Form Builder Module

By shane
Tue, 2013-01-22 23:13
3 comments
Daily Dose of Drupal Episode #92

The Drupal 7 Form Builder module is a handy module for those new to building forms with the Drupal Form API. The module provides a nice, centralized interface for building out Drupal forms.

In this episode you will learn:

  • What is the Drupal 7 Form Builder module and why might it be useful
  • How can the Drupal 7 Form Builder module be used to export Drupal 7 Form API code.

Hello everyone and welcome to another Daily Dose of Drupal, as always I’m Shane, you can follow me on Twitter at smthomas3, you can also go to codekarate.com and sign up for the newsletter if you haven’t already.

Today we’re on Episode Number 92, I’m going to quickly go over a module that is called the Form Builder Module and it’s on drupal.org/projects/form_builder and basically the goal of this module is to be a centralized interface for building out various form elements.

However right now I believe it only works for … actually exporting the Form API code that basically gives you the PHP Code that you can drop into a module and use, it also can be integrated with the Web Form Module I believe. I’m just going to go over the first option and how you can use it to build or at least get a baseline of some of the PHP code necessary to implement your own custom form in a custom module and it doesn’t necessarily provide the cleanest of all Form API code but it can get you started so we’re going to go ahead and just take a real quick look at what it can do.

It’s kind of a fancy looking module once you get it going and it’s all Ajax and Java Script based so it’s pretty nice and easy to use. I’m going to go ahead and turn the Form Builder Module and this module is more of a framework so without any of the other implementing modules it will not really do anything so I’m also going to turn on the Form Builder examples module and in the future episode I may cover its integration with the web form module as well.

But for now we’ll just stick with the examples module. After I install that there’s another … there’s a link that’s been added to this navigation section and I click on that and it’s a form builder example.

It comes stocked with a bunch of our form elements I already added, I’m going to go ahead and just get rid of some of this so we can start with the blank form. So I’m going to go ahead and start by adding some checkboxes, you can then edit this and then I’ll add a couple options here, you can also set it so you can customized the keys of the actual values which will give you the ability to actually customized what will be sent in when it’s selected, not just what’s displayed to the user and you can also make this required so they have to select one.

Now that I close that you can see I have check boxes here, I can click on this Export tab anytime and it gives me the code here that I can drop in to a module and it’ll actually be a working form in that … once you copy this in and you get it set up it’ll just work. The only thing that you need to notice is this is only going to give you the code to display the form.

It’s not necessarily going to give you the code of how to handle where the data goes once it’s submitted or any other extra validation you may need, it’s also … it does just name this a random … looks like a collection of numbers maybe be based on the timestamp so you may need to change this to be something a little more readable for you so you can better handle the output of the form and you’ll also going to make sure you add a Submit button if you do somehow take this form code and drop it into a module.

We’ll go ahead and add a couple of other things here; so you can see as I’m changing this it is modifying the actual form element here, you can easily rearrange things in the Form Builder, we can also make an image if you want a number select variable, have a number field, you can add a prefix and you can see it’ll add a prefix here, you set the default value.

So as you can see it’s very useful, easy to use, allows you to easily and quickly build out various form elements and it basically saves you potentially some time if you’ve never built out a form with the Form API before this can be a good starting point. If you already built out many form structures you probably are not going to find a lot of use for this, it’s kind of more of … in the example modules is more of a proof of concept to try to provide that centralized Ajax interface for building out various forms whether it’s web forms or in this case just building out form code that you can then export and put in your own module.

But it is kind of handy especially if you are unfamiliar with building out Form API structures and you want to have just the example code to go off of when you’re building your own, it can give you that good head start and in some cases you may find it to be actually faster than writing the code yourself.

Maybe you can build you form here, export it out and drop it into a module much faster than writing the code yourself. I’ll go ahead and give it a try and see what you think, see if it is useful. I’ve never really used it on forms because I didn’t know about it until recently but I can see how if you are a new comer and you’re trying to learn how to build forms using the Drupal Form API getting a little head start with the code and then examining what code is given to you here can be potentially useful and it can obviously give you a quick jumpstart on giving those longer forms out.

So that’s it for this time on the Daily Dose of Drupal and we’ll be back again next time. Thank you for watching.

5 Secrets to Becoming a Drupal 7 Ninja

Comments

Thanks for the effort you put into creating this video and I appreciate your expertise on the subject. But one thing that I would like to know is what does 'drop it into a module' mean?

Considering this app is best suited to the inexperienced user (that's me) a clearer explanation would have be great. Please elaborate on the phrase, as I think I could really use this module.

Thanks again.

Ruth

Post new comment