Custom Fields in Drupal Event Signups

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 FieldsTLC 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.

See Also

comments powered by Disqus
Last updated: November 30, 2023