Blog: DiA
Integrating Drupal, Democracy in Action, and i18n
Making It Possible To Collect User Information in Five Languages
Making It Possible To Collect User Information in Five Languages
The United Nations Millennium Campaign gathered millions of people around the world this week to stand up against poverty and in support of the UN’s Millennium Development Goals. We were heavily involved in developing the Stand Up Speak Out campaign's Drupal website, StandAgainstPoverty.org, and had a great time adding some interesting and important features to the site.
A very important part of that development work revolved around the need to make the site viewable in five languages (English, French, Portuguese, Spanish and German, for those keeping score). The real trick was that the campaign wanted to collect information from the people visiting their website using their CRM system - Democracy In Action's (DiA) Salsa toolset - but the toolset only handled information in English. I'll explain in this blog post how we used Drupal to get DiA's CRM to also handle information in the site's other four languages.
We used a number of i18n-related modules to make translation easy and integrated several forms created using DiA in a way that made the forms i18n-friendly for fast translation. The approach described below is not ideal, but it was executable in the short timeframe in which we were operating. Ideally, we'd make better use of DiA's API so that form-creation is accomplished in DiA's Salsa interface, and Drupal could query the details of the various form pages and build Drupal forms on the fly with that data.
Given our time constraints, we built the forms manually. For anyone who needs to quickly build forms in Drupal, I can't recommend the Forms API Quickstart Guide on Drupal.org highly enough - it helped shake out the cobwebs.
Building the two forms was straightforward enough. I began by adding a menu callback to my module, then added the page building function, and then built my form out.
// Menu callback
$items[] = array(
'path' => 'path/to/my/form',
'title' => 'DiA Signup Form',
'callback' => 'dia_signup_page',
'access' => TRUE,
);
[...]
// Page building function
function dia_signup_page() {
return drupal_get_form('dia_form');
}
There are several things to keep in mind here. First, in order to make these forms available to the l10n_client for easy translation, you will need to wrap your field titles in Drupal's t() function.
// Sample form field
$form['dia']['First_Name'] = array(
'#type' => 'textfield',
// Make translation easy--always use the t() function!
'#title' => t('First Name'),
'#size' => 30,
'#maxlength' => 64,
);
In Drupal, you can save your hidden form fields and add them in your form submission function, thereby eliminating another place where unexpected client input may cause headaches (or worse). DiA forms make heavy use of hidden fields when custom data is collected or when user submitted records are added to DIA groups.