Dec
12
(2006)
We’re using the Event module to list our workshops at the Teaching & Learning Centre, and the Signup module to let people register to attend workshops (or other events). It’s working really quite well, but we needed to add some extra fields to the registration form so we could track Faculties, Status, etc…
“Sure,” I said, “Drupal’s open source, so we should be able to add any fields we want. Worst case scenario? We’d have to fork Signup.module and maintain our own version with our custom fields in it.”
I then proceeded to drag my feet, not looking forward to having to maintain a module for something as simple as adding some custom fields. Maybe I could use the FormsAPI and insert the fields through some custom code?
So, I poked through the signup.module source code to see what would be involved. I’d braced for some rather convoluted and involved hackery. I blocked my schedule for the day so I’d have time to dedicate to the task.
Then, I saw that the module developers had already done the work for me. They implemented the signup form’s fields as a themable method, letting me override it on a per-theme basis. Without having to touch the code for the module itself. Brilliant. Absofrakking brilliant. So, I added this code to our theme’s template.php file (the theme is called “uofc_thisisnow”):
function uofc_thisisnow_signup_user_form() {
$form['signup_form_data']['#tree'] = TRUE;
$form['signup_form_data']['Name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#size' => 40,
'#maxlength' => 64
);
$form['signup_form_data']['Phone'] = array(
'#type' => 'textfield',
'#title' => t('Phone'),
'#size' => 40,
'#maxlength' => 64
);
$form['signup_form_data']['Faculty'] = array(
'#type' => 'textfield',
'#title' => t('Faculty or Department'),
'#size' => 40,
'#maxlength' => 64
);
$form['signup_form_data']['Status'] = array(
'#type' => 'select',
'#title' => t('Status'),
'#default_value' => t('Faculty Member'),
'#options' => array(
'faculty' => t('Faculty Member'),
'staff' => t('Staff'),
'student' => t('Student'),
'other' => t('Other')
)
);
return $form;
}
That results in a signup form that looks like this:
TLC Workshop Signup with Custom Fields
The beauty of this, since it exposes the full FormsAPI, we can add select menus, radio boxes, default values, etc… Without having to touch the code of the Signup module itself. Very cool stuff.
Comments
13 Responses to “Custom Fields in Drupal Event Signups”
Leave a Reply
You must be logged in to post a comment.

And can you tell us how the custom fields are being stored in the database? Serialized in a text db field?
Ah, yes. I forgot that part. Yeah. It basically just serializes an array of values into the signup_log table, using the form_data field, like this:
That gets turned back into a hashtable in PHP so it’s easy enough to call via arrayname['valuename'] convention to get the values back out (but it takes care of doing that automatically if you don’t want to do anything custom for display).
Thx for feedback and the nice article!
Cool stuff - but what calls function uofc_thisisnow_signup_user_form() ?
Jim - that gets automagically called by Drupal’s theming engine, triggered by a request by signup.module. It looks in template.php for THEMENAME_signup_user_form()
Excellent article thanks saved me alot of time
Great! Glad to help out, Simon!
Thanks This was very helpful.
hi,
big thanks for helpfull info!
PS: Link to http://api.drupal.org/api/HEAD/file/developer/topics/forms_api_reference.html is dead
i can not open this page.
Awesome, helped a lot! Wonderful you are man!
I am needing to do the exactly the same thing, but you lost me on where you placed the code for the edits. it sounded like in the theme template (in any particular place). More specifically how can I create several different signup forms using the same theme? Possible?
thank you so much, this was very helpful.
what if i want to make some fields required, how would i do that?
Thank you so much. I was looking to do something exactly like this and your solution came up. This was very helpful.