June 30, 2008

Bulk view

Hooray, figured out Drupal 5 multi-step registration form with validation and invites

The validation of multi-step forms in Drupal 5 was much less scary than I thought it would be, or maybe I lucked out by basing my code on something that already worked. =)

I had spent last Thursday and Friday searching the Internet for people’s blog posts about the topic. I came across exact descriptions of the problems I encountered, but no solutions–only notes about critical bugs in Drupal 5. Asking the developers in #drupal didn’t yield any tips, either. They told me to get ready for a world of pain.

Then I remembered that the password-reset module used a multi-step form, and validation actually worked. I had already incorporated part of the source code into one of my modules, and it was easy to extend that example. I defined a new multi-step form in my PHP code as a replacement for the system form in user/register. There were some complications around the fact that other modules modify the behavior of user_register, but I got the code to validate and submit the data. And it worked!

No code snippet, sorry. Too many interactions for me to explain neatly. Some hints:

  • You can use logic to set the value of $step.
  • Pass information to the next step using hidden fields.
  • Make sure the step field is included in your form template. Watch out for this if you’ve got a form template that specifies all the fields explicitly.
  • Captcha uses hook_form_alter to add a captcha based on the form_id. It doesn’t know about steps. You’ll need your own hook_form_alter to unset the captcha if you don’t need it on the other steps. Make sure your module runs after captcha by changing the weights in the system table.

So now I have a multi-step form that can skip step 1 (employee verification) if a valid invite code is provided, asks for CAPTCHA once, and does all the validation and user registration magic. Hooray!

Quick weekly report, week ending June 29, 2008

Next week, I’m going to write these weekly updates on Friday or something, so they don’t get squeezed into Sunday night. =)

This week:

  • Work: Welcomed new team member on board. Also, a CSS person joined our project team, hooray!
  • Work: More Drupal work, yay! Going through bugs reported in QA process.
  • Fight/fitness: headlocks, knees, 360′ defenses
  • Fun: Three movies (so spoiled!): Wall-E, You Don’t Mess with the Zohan (surprisingly funny), and Kung Fu Panda. Shopped for a few things to make life even better.

Next week:

  • Drupal, Drupal, more Drupal. =)
  • Promised to map Web 2.0 for business resources within the company. Time to break out the visualization tools.
  • Promised to put together a guide for speakers.
  • Promised to put together some resources for new hires.