Web Form Logic in Drupal
A recent client requested a user-friendly (aka, web interface) means for creating web forms, logical workflow between forms and form-pages, and user-specified actions to invoke upon completion of these forms. What I'm getting at here is a solution comparable to Form Assembly, JotForm, and Wufoo.
The client wanted to move away from the above solutions in order to have a solution that's integrated into his site, rather than embedded using iframes, such that the data is accessible in whatever form he so desires. Being the Drupal nut I am, we decided to use ye ol' CMS. However, I soon bumped into a little problem... Drupal web forms aren't quite there yet. For those of you not familiar with this ongoing complaint, to which I came late on the scene, let me fill you in:
Drupal really depends on a two contributed modules: CCK and Views. CCK (content construction kit) allows users to define different content forms with different fields. For example, a cck-built content type would be a form that has a textfield called "Name," and number field called "Zip Code," and so on. Views lets the user specify how this content is displayed on different pages, the sort criteria, the filters applied, etc. Seems like a natural-enough solution for the aforementioned problem, right? The downside to CCK is that its robustness tends to get in the way when you're trying to create simple things... like forms... rather than robust things, like realty home-listings with Google maps, prices, nested views, etc. Every page of every form is its own content type, and every filled-out form is its own node... this creates some hectic database clutter, and kinda scrambles you when you're working with CCK and Views for their designed use-cases. However, the upside to CCK is the external module integration, especially by way of a little something called Worlfow-ng. Workflow-ng ("next generation") allows users to specify field-specific logic in a series of workflow steps, and a slue of out-of-the-box actions to perform at any given step (as well as an API for specifying custom PHP actions). An example scenario would be:
if the user clicked "yes" for question 1, "no" for question 2 then go to the podcast page otherwise email the site administrator with the following information: "blablablabla"Of course you don't write it out like that, the web interface has buttons and checkboxes... but you get the gist. In short, this is exactly what I need. But... to go with this solution, I'd have to incur the cost of big fat ugly forms, where each page of each form is considered it's own "content type," stored all over the database for the sake of extensibility, etc.
For this reason, one "quicksketch" created a nifty module called Webform. Webform allows you to create simple forms, with a much slicker interface for building such forms than what CCK offers. The resultant forms are nodes rather than content types, the filled-out forms are aggregates under those nodes, and each form only requires one node for multiple pages -- all of which drastically saves on database clutter. The forms are much more intuitive to build than via CCK, and statistical reports are even generated for submitted forms. Quite sexy. There is one issue here, that the resultant form isn't quite as robust as a CCK-generated content type. Do I sound like a flipflop yet? Like I want to have my cake and eat it too? What I mean by this is that Webform is not extensible... if in the future I wanted to add a different field type, I couldn't just hit up the CCK-geared modules repository and nab a field-type. But more importantly, I can't use workflow-ng. Webform.module does let you add PHP logic for the forms, but it's not quite as intuitive as workflow-ng.
So the last alternative? Building the damn forms myself, using Drupal's built-in FormAPI. This is probably what a lot of programmers will do on their own sites, but it's not the recommended solution nowadays. Think of FormAPI as the method for building the forms for building forms. In other words, say we're using CCK to build web-forms, well someone had to build the administration form you use for building a CCK webform, right? In other-words, FormAPI is the programmer's enabler of webform solutions, but not to be used for anything I've been discussing in this post.
Ultimately, given some more (or easier) control over the CCK content types such that one can make content types multi-page and form-friendly, I think that the CCK solution will be the be-all-end-all. And eventually I'll stop whining and get off my ass to develop some module to provide that functionality. But until then, let me wrap up these alternatives with what I believe to be the ideal solution for three different scenarios:
- Webform.module: Your client needs to be able to create very simple forms -- little or no field-logic. You can still use workflow-ng to provide post-completion actions (like page-redirects and shooting off emails), but only PHP for the form-filling process itself.
- CCK + Workflow-ng: Your client wants to be able to create multiple forms, driven by logical workflow that acts upon the fields themselves (aka, if Field1="Yes" and Field2="No", etc). This is the ugliest, but most robust solution, and provides the client with all the power he so desires.
A few quick words if you decide to go the CCK route: get the auto node title module so your end users don't have to provide a title for the forms they fill out, lol. There's something floating around called CCK Wizard that lets you split your content types into multiple pages, but it's broken. If it was fixed, there would be some uber points for the CCK route. Also, I've heard it recommended to use Pageroute which allows the client to specify that one content type leads to another upon completion (think multi-step forms). My opinion is to not use this module, since workflow-ng provides that very functionality, along with all of it's logic sexiness.
Last, a bit off topic, but somewhat related: Actions + Workflow. If you're a Drupaler, you've likely seen these modules. They're not really an ideal solution for the situation at hand, and let me explain. Workflow-ng is something of a combination of these two modules, but with out-of-the-box defaults. Think of the actions/workflow combo as requiring PHP-customized actions based on given logical workflow steps. Very similar, but with that keyword "PHP-customized" being the real difference between actions/workflow and the workflow-ng module. Workflow-ng still lets you program custom workflow steps and actions, but it provides more defaults to work with. Honestly, past that I don't really know the difference between the actions/workflow combo and workflow-ng, maybe someone can inform me. Also, I think that actions.module made it into core for Drupal 6 (and therefore don't bother with the contributed module???) and I also think that the workflow module is being fazed out to the new core triggers module. Correct me if I'm wrong on either of these, but that's my $.02 on why to use workflow-ng instead of actions/workflow.

Term Papers
There's something floating around called CCK Wizard that lets you split your content types into multiple pages, but it's broken. If it was fixed, there would be some uber points for the CCK route.this is a biggest problem.
http://www.energytalkradio.com
This module is an AJAX front-end for building backend forms that the coder will then splice into his/her custom module's code. It's no different from actually programming a form using FormAPI, except that the building process is easier.
Thank You
Thank's for your great article.
To use a steam-hammer to
To use a steam-hammer to crack nuts.
very funny
very funny
thats right mate lol!
thats right mate lol!
I have to say, you did a
I have to say, you did a really nice job on explaining something that can be really tricky at times. There are times that I struggle with wrapping my head around topics like the this.
Thank you for summing it up well.
thanks for sharing
thanks for sharing
It's quite possible..
It's quite possible..
what is lol
what is lol
'lol' means
'lol' means 'smile'
immobilier maroc
i mean :-) immobilier maroc
i mean :-)
immobilier maroc
lefnire, I too have been
lefnire,
I too have been spending sleepless nights brooding over finding a viable forms solution both for myself and a client's website. I am a Macintosh consultant and deal with networking, systems administration etc. and not into programming (neither do I have the patience to go down that path - atleast not now!). I am a big fan of Drupal, its elegance, flexibility (esp. compared to Joomla!), its extensibility etc. I have used CCK and Views to create some great solutions.
Ah! the day someone comes up with a forms solution for Drupal. During my travels over the web I have found some really excellent solutions. I'll mention it here just in case you have not come across them (and hey! for your inspiration too!): Frevvo is really great. FormSpring too. Both of these are not only great but address one of the most vexing issues with forms - that of creating conditional branching forms. I found Wuffoo (that you know of) to be really pleasing aesthetically but pretty basic feature-wise. Also the two that I mentioned are subscription-based non-customer hosted solutions. I am still searching for a software that I can purchase and host myself (that way I have control over the storage of data).
Now on with my search....
Thanks!
Kenneth.
good to know! i'm starting
good to know! i'm starting to wonder if those 3rd-party webform solutions might not be the best way to go about this... why have a webform module for every CMS when they can all piggy-back on existing solutions. like you said, too bad they're hosted without access to the data.. maybe someone will come up with an open source package & drupal devs will write an integration module, similar to gallery2.
Anyway, I played with those for a few minutes... FormSpring especially is sexy! actually, been a while since I posted this, and since then either webform.module has gotten better or I've started to realize it's potential. I ended up using webform.module in my circumstance, the only con for using it being lack of user-friendliness on the form-logic space; however, this turned out to arise much more seldom than I thought, and it turned out to be no biggy for me to enter custom PHP in that logic box under advanced settings per webform when the client needs it.
I've already found a
I've already found a solution for this "tackling"-problem: There's an Ajax Tool called "JAPT" or something like that. I've seen it while I was visiting a friend of mine and it looked like THE solution for that problem you described. Try googling, I think you will find it quickly...
Greetings from Germany!
Mail: port01 dot lavazza at gmail dot com
Website: http://www.fitness-zentrale.de/fitflops/fitflops.html
Hi, I am interested in
Hi, I am interested in getting your opinion on something. I have a client who is looking to build a type of job application system. Here are the simple details.
There are two types of applications. A 1st Time Application and a Re-Application. A user creates an account, and they choose whether or not they have applied before. If not they get the 1st time app. If they have they get the Re-App. The user needs to be able to create/save for later they app.
Also, when a user submits a first time app the next time they go to fill out an app they automatically get the re-app (profile changes).
They should aslo be some logic involved, if they answer yes to a question they get more questions etc...
Also, for employement records (required) they should be able to create many of them.
And the app is split up into multiple pages or sections.
Also, the client wants to be able to edit these apps down the road, add remove questions.
And now the kicker, they need to have a printer friendly version that prints in a very specific format.
Any ideas, is drupal with CCK/Workflow NG the way to go? Is this level of customization more than drupal/cck/workflow ng can handle.
Appreciate your time very much,
~ Tom
My spec is almost identical
My spec is almost identical to yours, & is essentially the whole reason for this post. In yours and my case, I do think CCK/Workflow-NG is the way to go. One reason (and I haven't persued this in Webform.module) is that each page of each form, while cluttering your database, is a content type of its own, making it easier to save progress along the way. You'd have to somehow 1 submission per form content type, with page routing between them, to each registered user. For printer-friendly formats, use print.module, which also has pdf output in Drupal6.
Thanks, what is not clear
Thanks, what is not clear to me is how to do the for logic, for example if they have the question:
Have you ever been arrested? Which is a radio button for yes/no.
If they choose "yes" then a div will appear that has a bunch more questions that will have to be answered.
Also, I am not clear how I would do the Education or Employment records where in each application there can be many of them. Would these be another node type? That each user can have multiple of?
My email address is: tom (dot) cocca (at) gmail (dot) com
I would love to ask you a few more questions, like how would I do the menu switching between the two applications, etc...
Thanks for your post, I'll check out this option today. Not quite sure how workflow NG works at all.
If you do decide to tackle
If you do decide to tackle the problem yourself, you might want to check out the Ajax Form Builder module (a Google Summer of Code project from 2006). It looks more-or-less abandoned, but it might be a good starting point or at least a point of reference for what mistakes to avoid.
I'd love to see a solution that combines the best of Webform, CCK, Form Assembly, and Form Tools.
- Matt V.
http://www.minezone.org/
Looked at it, & actually not
Looked at it, & actually not the thing I need. This module is an AJAX front-end for building backend forms that the coder will then splice into his/her custom module's code. It's no different from actually programming a form using FormAPI, except that the building process is easier... it's still meant for a developer, not a client.
Good call, I was looking at
Good call, I was looking at that module earlier and bailed for the same reason you just mentioned. Also, seeing as Drupal 6 is carrying on with FormAPI, sexfying it with AHAH & whatnot... means Drupal Forms are here to stay, and not to be replaced with CCK. So while it appears CCK is the best current solution for web-form building, if one wanted to get involved it seems that giving FormAPI a web interface (as with that module you mentioned) would be the best way to go about it.
One of the best things I have
One of the best things I have read on the subject.
I have been wasting days and days of projects because of the stupid problem of not being able to paste a html form into the content area of a standard story or page node.
If you could do that, none of my problems would exist.
Very insightful and well presented explanation of the dubious reliance of CCK and Views (why make a tool to let other people make a tool right?) and the numerous issues with the well regarded webforms module.