Mollom

AHAH helper module

AHAH-powered forms were virtually impossible in Drupal 5 (see the note though). In Drupal 6, this is much easier, thanks to the #ahah property. However, it still is really painful to actually use it.

The flaw

You have to write a menu callback for each AHAH-enabled form item of your form. You have to repeat small variations of this piece of code for each callback:

  1. // Build our new form element.
  2. $form_element = _mymodule_add_something_to_form();
  3.  
  4. // Build the new form.
  5. $form_state = array('submitted' => FALSE);
  6. $form_build_id = $_POST['form_build_id'];
  7. // Add the new element to the stored form. Without adding the element
  8. // to the form, Drupal is not aware of this new elements existence and
  9. // will not process it. We retreive the cached form, add the element,
  10. // and resave.
  11. $form = form_get_cache($form_build_id, $form_state);
  12. $form['somewhere']['very']['deep'] = $form_element;
  13. form_set_cache($form_build_id, $form, $form_state);
  14. $form += array(
  15. '#post' => $_POST,
  16. '#programmed' => FALSE,
  17. );
  18.  
  19. // Rebuild the form.
  20. $form = form_builder('mymodule_someform', $form, $form_state);
  21.  
  22. // Render the new output.
  23. $subform = $form['somewhere']['choice'];
  24. $output = theme('status_messages') . drupal_render($subform);
  25.  
  26. drupal_json(array('status' => TRUE, 'data' => $output));

Ok, it does make sense. But it takes some time to get used to – too much – and is a treshold that's big enough for many developers to just not implement AHAH forms. It simply shouldn't be this hard.
This current approach of AHAH forms in Drupal is time consuming, hard to maintain and hard to write tests for.

Drupal.behaviors + jQuery: multiple buttons with the same name

While working for Mollom, I faced the problem of needing multiple buttons with the same name. In my case, this was an absolute necessity on an advanced multi-step form. Sounds super … easy, right? But HTML doesn't support this!

Thankfully, the combination of Drupal.behaviors and jQuery makes it easy to create a work-around! jQuery makes it easy to write the necessary code, Drupal.behaviors makes it trivial to ensure it keeps working even when new content has been added to the page (i.e. after an AHAH callback).

Working at Mollom!

As some of you may already know, I'm working for Mollom now (summer position).
The reasons for that should be obvious:

  • It's Drupal work.
  • I get to work with Dries. No explanation needed here I think.
  • I get to work with Ben. Don't know him? Remember this: he's really smart and that shows in his machine learning skills and research (he's got a Ph.D. in that field). He made Mollom's algorithms outstanding.

So why I was I hired, without even having an interview?
Well, because certifications don't say much about a person's real skills. They only indicate a base level. Even college/university diplomas are becoming less valuable. It's your real experience that matters. And you can see my real experience in my Drupal.org profile. You can tell that I have a lot Drupal experience, and you can find out the quality of my work by looking in my projects' issue queues and the accompanying code.
That's what really matters.

From day 2, I've be doing daily calls with Dries, and sometimes with Ben too. I really like this way of working, and actually I wouldn't have taken the job if I couldn't do it this way: there's nothing I hate more than losing time because of transportation.
If I have to travel more than one hour per day, I get annoyed. More than 2 hours and I'll just quit.

The first day had both crazy (the morning) and cool times (the rest of the day). So I jotted down what happened that day. To read it, continue after the break.

Mollom: spam killer minus the annoyance

I'm late to the Mollom announcing party, because I was on a vacation. Nevertheless, I hope I can still interest some of you with a slightly different angle.

The major issue with spam prevention is that it often (currently virtually always) involves extra steps for normal users. And more steps means less participation. Less participation means less traffic. And less traffic means less popularity, revenue and whatnot. So clearly there is much to be gained to prevent spam without annoying normal users.

Syndicate content