Building forms with cck, actions and workflow
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
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!
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
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
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?
Thanks, could you give a url demo for what what have achieved, it will give a visible feel.
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.
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.)
@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.