Dynamic Webform Select list
Just thought this was worth sharing.
The goal was to populate the Feedback form (Webform Module) with the Email and Department name (cck fields) from the Content Type Contact. The reason I wanted to use this node type is that it stores the email and department name of all the staff and is used by other nodes to reference. I like using nodes more then profiles but that could work as well for sure.
For example if there is a node about energy audits the client could reference which department to contact with questions. This way the client could update the one node for that Contact and at the same time update the Feedback form and all nodes the reference that Contact Node.
Pretty simple idea and the Webform module and that fact it is so flexible made it really easy to hook and fill the select list. Here is a video of how it looks and works http://blip.tv/file/3914827
Below is the code (2 functions) to populate the select list in my case. But you get the idea.
function rvtc_contacts($webid = 'NULL'){
$webid = '434';
/* these are the fields */
$departmentfield = 'field_department_value';
$feedback = 'field_feedback_value';
$email = 'field_email_email';
$sql = "SELECT {$email} as email,
{$departmentfield} as department
FROM content_type_contact
WHERE {$feedback}
LIKE 'yes' ORDER BY department";
$result = db_query($sql);
while($data = db_fetch_object($result)){
$output[$data->email] = "{$data->department}";
}
//$output = array('test'=>'test1', 'test2'=>'test2');
return $output;
}
function rvtc_form_alter(&$form, &$form_state, $form_id){
if($form_id == 'webform_client_form_434'){
//print_r($form_state);
$form['submitted']['list_of_department']['#options'] = rvtc_contacts();
}
}#drupal
Faceted Search
Author Profile

Not counting my Commodore 64 years, I began my IT career when Windows 95 hit the scene and Google was just a glimmer on the Californian horizon. I discovered Drupal four years ago when it was giving Joomla a run for its money.
At the time, I was working as the IT manager at the National Priorities Project (NPP). We were using Joolma and getting about 200,000 visitors a month and the site was not scaling well. I saw the limits of Joomla and the promise of Drupal 4 with its taxonomy system, clean urls, and security features. I converted NPP to Drupal and migrated their main database, http://nationalpriorities.org/nppdatabase_tool, from webobjects to a Drupal-friendly structure in MySQL. Still not satisfied, I moved NPP’s constituent data (including their 25,000 member email list) out of the expensive Raiser's Edge and into the free and open source CiviCRM 1.8, saving the company money that it was spending on their desktop software.
Thus began my commitment to supporting non-profits by creating affordable, custom-built content management systems in Drupal and CiviCRM. I founded River Valley Tech Collective as a collaborative team of other like-minded techies to provide Drupal-driven sites to a wider range of non-profits, educational institutions and local community organizations.



