Building forms with cck, actions and workflow

Posted by Digett on July 03, 2007

We just finished building a simple form application for a client. Previously we have been big fans of webform.module, but this time we decided to go another route. After seeing some posts around drupal.org about using a combination of cck, actions and workflow to accomplish some of this same functionality, I decided to give it a shot.

First some background on what we're trying to accomplish. Users should be able to create an account, login and create a new application. The user should be able to update and save this application without actually submitting it. Once the user decides to submit the application, an email should be sent to a specified email address and the user shouldn't be able to edit it after this point. Then the reviewer should be able to see these submissions and mark them as reviewed. No one but admins and reviewers should be able to see any one else's application at any point.

Here is a break down of what I did to accomplish it.

First I created a new content type named Application. I set the default settings for this type to be unpublished by default and also to create new revisions. I then proceeded to create all the necessary fields (about a million of them!). This seemed much easier than webform's way of creating fields. More than once have I created a bunch of fields on a webform and then mistakenly hit the back button or clicked an errant link without submitting the webform node form, and subsequently lost all my work.

I then noticed that I really had no use for the title and body fields. Simple enough. I removed the body field from the content type settings page. For the title, i used a nifty little module called auto_nodetitle to give titles a default value and hide the title field. The title I used was "Application for [username]", using [username] to insert the name of the current user. If the token module is installed, then you can use many different tokens in your replacement title. Pretty cool.

Next up.. Actions and Workflow. I installed and enabled actions, workflow and workflow access (included in the workflow package) modules. I started off by creating a few simple actions (admin/build/actions), one to send an email, one to display a "Saved" message to the user and one to display a "Submitted" message to the user.

Then I created a workflow (admin/build/workflow) called Application Submission, set my Application content type to use this workflow and added 3 states (Saved, Submitted, Reviewed). The allowed transitions were (creation)->saved, (creation)->submitted, saved->submitted for authors, and submitted->reviewed for the reviewers role. I then hooked up the actions I created earlier to these transitions. The saved message was attached to the (creation)->saved transition, the submitted message to the Saved->Submitted transition, and the email action also to the saved->submitted transition.

Next up was workflow actions. First off, this module is awesome! It allows you to set up access control to nodes based on workflow states. I allowed node authors (form submitters) to view their applications in the saved and submitted states, edit only in the saved state and never delete. I allowed the reviewer role to view applications in submitted and review state, but only edit in the submitted state. I also disallowed regular users from viewing/editing any applications but their own.

The last thing I did, was to enable the bio module. This module lets you specify a content type as a user's "bio". What this actually means is that each user can have only 1 node of the specified content type. I wanted each user to only be able to create a single application, and be able to get back to edit that application easily.

I also created a view for the reviewers to easily see a list of all outstanding applications. This was simply a table view with workflow state, node title, modified time, and edit link for fields. I used node type and workflow state as filters and exposed the workflow state filter so the reviewers could do their own filtering.

So without writing any code, I was able to create this somewhat advanced form functionality. I did end up writing some code, basically to theme the form and node pages to look more appropriate. Thanks to the authors of all these wonderful modules for making my work easier.

MONTHLY MARKETING INSIGHTS.

Get thought-provoking and actionable insights to improve how your firm makes a connection with your customers.

LEAVE A COMMENT

The content of this field is kept private and will not be shown publicly.

Plain text

  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
Submitted by Guest on Sun, 11/09/2008 - 3:56pm

I've been using Drupal for about 6 months now and have a number of production sites under my belt. This article is superb. Great links, enough tech without getting bogged down.
Brilliant!

Submitted by Guest on Thu, 01/08/2009 - 1:29am

You mentioned that they could "save" and "submit". When anonymous users fill out a new content type called "contact form" on my website they are only able to "preview" and "save". Any idea on this additional state that you seem to have found?

Thanks,
Chris, burleyc1 -[a@t]- gmail.com

Submitted by Guest on Tue, 07/14/2009 - 10:29am

how do you get different buttons using the cck. In Webform it is really easy, but in cck I just see preview and save.
Thanks,
Michael

Submitted by Guest on Sun, 09/20/2009 - 8:36pm

Hi there,

I have the same question - I'd really like to change the label on the buttons. Does anyone have an idea how to do this?

Submitted by Guest on Tue, 04/20/2010 - 5:38am

Thanks, could you give a url demo for what what have achieved, it will give a visible feel.

Submitted by Guest on Fri, 01/14/2011 - 9:09am

I don't know if he used the save button, but if you are using workflow module, you don't really need a save button. Once the transition state is changed, it can trigger whatever response the save button should have.

So for a reviewer to approve the process is simple a matter of selecting if she wants to change the state from saved --> submitted and saves the node normally. this change of state should trigger action you described in your workflow settings.

Submitted by MD shahidul alam on Sat, 12/31/2011 - 1:57am

Thanks for your nice tutorial . I am working with a office portal where i need to the workflow to be applied. I followed your instruction but when the submitted application can not accessed by reviewer though the reviewer has all permission and all the access to all the content type. Could you please help me on this case. Reviewer get the message when try to access submitted form.( Access denied
You are not authorized to access this page.)

Submitted by Art Williams on Mon, 01/02/2012 - 8:30am

@MD Shahidul alam: This tutorial is 4 years old and is likely for an unsupported version of Drupal. There is probably an easier way to accomplish this now. Search http://drupal.org for your answers.