Signup form using CCK

Using CCK, in particular node reference, it is possible to relate data types to each other, just as you would do in a relational database. For example, create a content type song, and a content type artist, and in song put a node reference field to artist. Because in Drupal a field may have multiple values, it is also possible to do this the other way around, eg. put in artist a node reference field (with multiple values) to song. This is against the principle of normalized relational databases (because of the fact that multiple values are not allowed), but it is more intuitive for an end user. This node reference field can show itself as a select list, or an auto completion text field. If you create a view, and specify this node reference field as a required relationship, and in song specify to use this relationship, then the data of these 2 content types would be joined automatically, so you can generate songlists grouped by artist.

So if you think about it, you can store any data in a content type (aka node type). That includes data from forms. For things like signup forms it is not really necessary to install a seperate module for this. Just create a new content type to store your signup data.

Let's create a content type called signup. Add a node reference field, and select the content type used to store the events. Later on, when someone creates a signup node, he/she will get a select list with all the events you can signup to (all node titles of for example node type "event"). For more experienced users, it is also possible to use a view instead of specifying a content type. With views it is for example possible to only select events in the future (no past events). Add more CCK fields if needed, for example first name, last name, number of people joining you etc..

This works ok, however usually you would want a direct link called "Sign up now!" (or something like that) in the event node. This link would take you to the signup form, where we would like to "prepopulate" the node reference field to the correct value: the event node where we came from.

The first step to the solution of this problem is to install the prepopulate module. With this module it is possible to specify default values for form fields on the node creation pages as arguments in the url. For example, in order to prepopulate  the title field with the text "foobar", you would add "&edit[title]=foobar" to the url. In the HTML source, search for the node reference field, and find the name attribute. If it is something like "field_signup_noderef[nid][nid]", then you need to add "&edit[field_signup_noderef][nid][nid]=xx" to the node creation url (watch the brackets). The "xx" needs to be replaced by the node id of the event node you are referring to. If all goes well, then the select list will show the node you specified on the url as default.

Next step is to generate this link automatically and put it on the event nodes. Copy "modules/node/node.tpl.php" to your theme directory. Copy the same file also to "node-event.tpl.php" (or whatever you called the content type where you store your events) in your theme directory. Edit the latter file and add the following after the content part:

     <a href="<?php global $language; print base_path() . $language->language;
        print $node->nid; ?>">Sign up now!</a>

Now, go to your theme settings and save the configuration (this will trigger something which causes the new template files to be read). Also in the performance settings, clear the cache. Add permissions to your users for creating signup nodes. Test it: create a couple of fake signups using the signup link on the event nodes. Create views for generating reports of signups. In order to export these reports to CSV files for use in spreadsheets, install the views bonus module, and enable the export module. To use this, add a feed display to your view (normally you would only use defaults, page or block), and under style choose CSV file.