--- modules/forms/forms.module	2005-12-15 20:01:42.768630000 -0800
+++ modules/forms/forms.module	2006-01-11 16:35:13.267355000 -0800
@@ -86,7 +86,7 @@ function forms_load($conditions = array(
  */
 function forms_save_field($field) {
   if (is_array($field)) {
-    $field = array2object($field);
+    $field = (object) $field;
   }
 
   $field_cols = array('ffid','fid','title','explanation','page','type','weight','required','flags','validation','options','multiple');  
@@ -147,58 +147,157 @@ function forms_delete($form) {
  * form for editing a field
  */
 function forms_field_form($field, $exclude = NULL) {
+  $form = array();
 
-  $output.= form_hidden('fid', $field->fid);
-  $output.= form_hidden('ffid', $field->ffid);
+  $form['fid'] = array('#type' => 'hidden', '#value' => $field->fid);
+  $form['ffid'] = array('#type' => 'hidden', '#value' => $field->ffid);
 
-  $output.= form_select(t('Type'), 'type', $field->type, _forms_get_field_types($exclude));
-  $output.= form_textfield(t('Title'), 'title', $field->title, 70, 128, t('The title will be shown in the user interface.'));
-  $output.= form_textarea(t('Explanation'), 'explanation', $field->explanation, 70, 3, t("An optional explanation to go with the new field.  The explanation will be shown to the user."));
-  $output.= form_textarea(t('Selection options'), 'options', $field->options, 70, 8, t("For select fields only. A list of all options - delimited by semicolons (e.g. red;blue;green). To have different labels from values, use colons e.g. 1:red;2:blue;3:green"));
-  $output.= form_checkbox(t('Allow multiple selection'), 'multiple', 1, $field->multiple);
-  $output.= form_weight(t('Weight'), 'weight', $field->weight, 5, t("The weights define the order in which the form fields are shown.  Lighter fields \"float up\" towards the top of the category."));
-  $output.= form_checkbox(t('Required field'), 'required', 1, $field->required);
-  $output.= form_select(t("Validation function"), 'validation', $field->validation, _forms_get_validation_types(), t("Name of a function to test the input value"));
+  $form['type'] = array(
+    '#type' => 'select', 
+    '#title' => t('Type'), 
+    '#default_value' =>  $field->type, 
+    '#options' => _forms_get_field_types($exclude), 
+  );
+  $form['title'] = array(
+    '#type' => 'textfield', 
+    '#title' => t('Title'), 
+    '#default_value' =>  $field->title, 
+    '#description' => t('The title will be shown in the user interface.'),
+    '#size' => 70,
+    '#maxlength' => 128,
+  );
+  $form['explanation'] = array(
+    '#type' => 'textarea', 
+    '#title' => t('Explanation'), 
+    '#default_value' =>  $field->explanation, 
+    '#description' => t("An optional explanation to go with the new field.  The explanation will be shown to the user."),
+    '#cols' => 70,
+    '#rows' => 3,
+  );
+  $form['options'] = array(
+    '#type' => 'textarea', 
+    '#title' => t('Selection options'), 
+    '#default_value' =>  $field->options, 
+    '#description' => t("For select fields only. A list of all options - delimited by semicolons (e.g. red;blue;green). To have different labels from values, use colons e.g. 1:red;2:blue;3:green"),
+    '#cols' => 70,
+    '#rows' => 8,
+  );
+  $form['multiple'] = array(
+    '#type' => 'checkbox', 
+    '#title' => t('Allow multiple selection'), 
+    '#default_value' =>  $field->multiple, 
+  );
+  $form['weight'] = array(
+    '#type' => 'weight', 
+    '#title' => t('Weight'), 
+    '#default_value' =>  $field->weight, 
+    '#description' => t("The weights define the order in which the form fields are shown.  Lighter fields \"float up\" towards the top of the category."),
+    '#delta' => 5,
+  );
+  $form['required'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Required field'),
+    '#default_value' => $field->required,
+  );
+  $form['validation'] = array(
+    '#type' => 'select', 
+    '#title' => t('Validation function'), 
+    '#description' => t("Name of a function to test the input value"),
+    '#default_value' =>  $field->validation, 
+    '#options' => _forms_get_validation_types($exclude), 
+  );
 
   // get extra form fields for 'flags'
-  $output.= implode('', forms_invoke_formapi($field, 'edit'));
+//  $output.= implode('', forms_invoke_formapi($field, 'edit'));
   
-  return $output;
+  return $form;
 }
 
-function forms_render($form, $edit = array()) {
+function forms_get_form($form, $edit = array()) {
+  $real_form = array();
   foreach ($form->fields as $field) {
-    $output.= forms_render_field($field, $edit[$field->name]);
+    $real_form[$field->name] = forms_get_field($field, $edit[$field->name]);
   }
-
-  return $output;
+  return $real_form;
 }
 
-function forms_render_field($field, $value = null) {
+function forms_get_field($field, $value = null) {
   forms_invoke_formapi($field, 'view');
   $func = 'form_' . $field->type;
   switch ($field->type) {
     case 'radios':
-      $output .= $func($field->title, $field->name, $value, _forms_options($field->options), $field->explanation, $field->required);
+      $real_field = array(
+        '#type' => 'radios', 
+        '#title' => $field->title, 
+        '#default_value' =>  $value, 
+        '#options' => _forms_options($field->options), 
+        '#description' => $field->explanation,
+        '#required' => $field->required
+      );
       break;
     case 'select':
-      $output .= $func($field->title, $field->name, $value, _forms_options($field->options), $field->explanation, NULL, $field->multiple, $field->required);
+      $real_field = array(
+        '#type' => 'select', 
+        '#title' => $field->title, 
+        '#default_value' =>  $value, 
+        '#options' => _forms_options($field->options), 
+        '#description' => $field->explanation,
+        '#multiple' => $field->multiple,
+        '#required' => $field->required
+      );
       break;
     case 'textarea':
-      $output .= $func($field->title, $field->name, $value, 64, 5, $field->explanation, NULL, $field->required);
+      $real_field = array(
+        '#type' => 'textarea', 
+        '#title' => $field->title, 
+        '#default_value' =>  $value, 
+        '#cols' => 64,
+        '#rows' =>  5, 
+        '#description' => $field->explanation,
+        '#required' => $field->required
+      );
+      break;
+    case 'textfield':
+      $real_field = array(
+        '#type' => 'textfield', 
+        '#title' => $field->title, 
+        '#default_value' =>  $value, 
+        '#size' => 64,
+        '#maxlength' =>  64, 
+        '#description' => $field->explanation,
+        '#required' => $field->required
+      );
       break;
     case 'file':
-      $output .= $func($field->title, $field->name, '', $field->explanation, $field->required);
+      $real_field = array(
+        '#type' => 'file', 
+        '#title' => $field->title, 
+        '#description' => $field->explanation,
+        '#required' => $field->required
+      );
       break;
     case 'checkbox':
-      $output .= $func($field->title, $field->name, 1, $value, $field->explanation, NULL, $field->required);
+      $real_field = array(
+        '#type' => 'checkbox', 
+        '#title' => $field->title, 
+        '#default_value' =>  $value, 
+        '#description' => $field->explanation,
+        '#required' => $field->required
+      );
       break;
-    case 'textfield':
     case 'password':
-      $output .= $func($field->title, $field->name, $value, 64, 64, $field->explanation, NULL, $field->required);
+      $real_field = array(
+        '#type' => 'password', 
+        '#title' => $field->title, 
+        '#default_value' =>  $value, 
+        '#size' => 64,
+        '#maxlength' =>  64, 
+        '#description' => $field->explanation,
+        '#required' => $field->required
+      );
       break;
   }
-  return $output;
+  return $real_field;
 }
 
 function forms_validate($form, $edit) {
--- modules/survey/survey.module	2005-12-15 20:06:14.094291000 -0800
+++ modules/survey/survey.module	2006-01-04 16:45:31.191465000 -0800
@@ -28,11 +28,11 @@ function survey_help($section = '') {
 }
 
 /**
- * Implementation of hook_node_name
+ * Implementation of hook_node_info
  */
-function survey_node_name () {
-  return t('survey');
-}
+function survey_node_info () {
+  return array('survey' => array('name' => t('survey'), 'base' => 'survey'));
+ }
 
 /**
  * Implementation of hook_perm
@@ -50,13 +50,13 @@ function survey_menu($may_cache) {
     $items[] = array('path' => 'node/add/survey', 'title' => t('survey'),
                      'access' => user_access('maintain surveys'));
     $items[] = array('path' => 'survey/submit', 'title' => t('survey submission'),
-                     'callback' => 'survey_submit',
+                     'callback' => 'survey_submit_response',
                      'access' => user_access('submit surveys'),
                      'type' => MENU_CALLBACK);
   }
   else {
     if (user_access('maintain surveys') && arg(0) == 'node' && is_numeric(arg(1))) {
-      $node = node_load(array('nid' => arg(1)));
+      $node = node_load(arg(1));
       if ($node->nid && $node->type == 'survey') {
         $items[] = array('path' => 'node/'.$node->nid.'/form', 'title' => t('form'),
                          'callback' => 'survey_fields', 'access' => user_access('maintain surveys'),
@@ -104,9 +104,10 @@ function survey_access($op, $node) {
 }
 
 /**
- * Impelementation of hook_validate
+ * Implementation of hook_validate
  */
-function survey_validate(&$node) {
+function survey_validate($node) {
+  node_validate_title($node);
   if ($node->email) {
     $emails = explode(',', $node->email);
     foreach ($emails as $email) {
@@ -121,33 +122,62 @@ function survey_validate(&$node) {
  * Implementation of hook_form
  */
 function survey_form(&$node) {
-  $output = '';
-  
-  if (function_exists('taxonomy_node_form')) {
-    $output .= implode('', taxonomy_node_form('survey', $node));
-  }
 
-  $output .= form_textarea(t('Intro Text'), 'body', $node->body, 60, 5);
-  $output .= filter_form('format', $node->format);
-  $output .= form_textfield(t('Path for "thank you" page'), "result_page", $node->result_page, 70, 70, t("This page is displayed after the form is submitted.  If you are not using clean URLs, specify the part after '?q='.  If unsure, specify nothing."));
-  $output .= form_textfield(t('Email address'), "email", $node->email, 70, 70, t("This email address will receive a copy of each survey submission. Multiple addresses can be specified as a comma-separated list."));
+  $form['title'] = array(
+    '#title' => t('Title'),
+    '#type' => 'textfield', 
+    '#default_value' => $node->title, 
+    '#size' => 60, 
+    '#maxlength' => 128,
+    '#required' => true,
+  );
+
+  $form['body'] = array(
+    '#title' => t('Intro Text'),
+    '#type' => 'textarea', 
+    '#default_value' => $node->body, 
+    '#cols' => 60,
+    '#rows' => 5,
+  );
+
+  $form['result_page'] = array(
+    '#title' => t('Path for "thank you" page'),
+    '#type' => 'textfield',
+    '#default_value' => $node->body, 
+    '#size' => 60,
+    '#maxlength' => 70,
+    '#description' => t('This page is displayed after the form is submitted. If you are not using clean URLs, specify the part after "?q=". If unsure, specify nothing.'),
+  );
+
+  $form['email'] = array(
+    '#title' => t('Email address'),
+    '#type' => 'textfield',
+    '#default_value' => $node->email, 
+    '#size' => 60,
+    '#maxlength' => 70,
+    '#description' => t('This email address will receive a copy of each survey submission. Multiple addresses can be specified as a comma-separated list.'),
+  );
+
+  $form['fid'] = array(
+    '#type' => 'hidden',
+    '#value' => $node->fid,
+  );
 
-  $output .= form_hidden('fid', $node->fid);
+  $form['filter'] = filter_form($node->format); 
 
-  return $output;
+  return $form;
 }
 
 /**
- * Impelementation of hook_view
+ * Implementation of hook_view
  */
 function survey_view(&$node, $teaser = 0, $page = 0) {
   $node = node_prepare($node, $teaser);
   $node->readmore = TRUE;
   if ($page) {
-    $form = forms_render($node->form, $_POST['edit'], $error);
-    $form.= form_submit(t('Submit'));
-    $form = form($form, "post", url('survey/submit/'.$node->nid));
-    $node->body .= $form;
+    $form = forms_get_form($node->form, $_POST['edit'], $error);
+    $form['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
+    $node->body .= drupal_get_form('survey_response', $form);
   }
 }
 
@@ -182,7 +212,7 @@ function survey_delete(&$node) {
  */
 function survey_fields() {
   $nid = arg(1);
-  $node = node_load(array('nid' => $nid));
+  $node = node_load($nid);
 
   foreach ($node->form->fields as $field) {
     $rows[] = array(array('data' => $field->title),
@@ -203,10 +233,6 @@ function survey_fields_edit() {
   $nid = arg(1);
   $ffid = arg(4);
 
-  if (count($_POST) > 0) {
-    forms_save_field($_POST['edit']);
-    drupal_goto('node/'. $nid . '/form');
-  }
   if ($ffid) {
     $field = db_fetch_object(db_query("SELECT * FROM {form_fields} WHERE ffid=%d", $ffid));
   }
@@ -215,36 +241,51 @@ function survey_fields_edit() {
   }
 
   $form = forms_field_form($field);
-  $form.= form_submit(t('Save field'));
-  $content = form($form);
+  $form['submit'] = array('#type' => 'submit', '#value' => t('Save field'));
+  $content = drupal_get_form('survey_fields_edit', $form);
+
   return $content;
 }
 
+function survey_fields_edit_submit($form_id, $form_values) {
+  $nid = arg(1);
+  forms_save_field($form_values);
+  drupal_goto('node/'. $nid . '/form');
+}
 
 /**
- * deletes a given field
+ * shows confirmation for deletion of survey field
  */
 function survey_fields_delete() {
   $ffid = arg(4);
   $field = db_fetch_object(db_query("SELECT * FROM {form_fields} WHERE ffid=%d", $ffid));
-  $nid = db_result(db_query("SELECT s.nid FROM {survey} s INNER JOIN {forms} f ON s.fid=f.fid INNER JOIN {form_fields} ff ON f.fid=ff.fid WHERE ff.ffid=%d", $ffid));
-  if ($_POST['edit']['confirm'] == 1) {
-    forms_delete_field($field);
-    drupal_goto('node/'.$nid.'/form');
-  }
+  $form = array();
+  $form['delete_text'] = array( '#value' => t("Really delete %field?<br/>", array('%field' => '<em>' . $field->title . '</em>')));
+  $form['delete'] = array(
+    '#type' => 'submit',
+    '#value' => t('delete'),
+  );
 
-  $content = form_hidden('confirm', 1);
-  $content.= form_item(t("Really delete %field?", array('%field' => '<em>' . $field->title . '</em>')), form_submit(t("delete")));
-  $content = form($content);
-  return $content;
+  return drupal_get_form('survey_fields_delete', $form);
+}
+
+/**
+ * deletes a given field
+ */
+function survey_fields_delete_submit($form_id, $form_values) {
+  $ffid = arg(4);
+  $field = db_fetch_object(db_query("SELECT * FROM {form_fields} WHERE ffid=%d", $ffid));
+  $nid = db_result(db_query("SELECT s.nid FROM {survey} s INNER JOIN {forms} f ON s.fid=f.fid INNER JOIN {form_fields} ff ON f.fid=ff.fid WHERE ff.ffid=%d", $ffid));
+  forms_delete_field($field);
+  drupal_goto('node/'.$nid.'/form');
+  return;
 }
 
-function survey_submit() {
+function survey_response_submit($form_id, $form_values) {
   global $user;
-  
-  $survey = node_load(array('nid' => arg(2)));
+  $survey = node_load(arg(1));
 
-  $error = forms_validate($survey->form, $_POST['edit']);
+  $error = forms_validate($survey->form, $form_values);
   if (!$error) {
     $responses = array();
     $rid = db_next_id("{survey_responses}_rid");
@@ -289,24 +330,24 @@ function survey_submit() {
 }
 
 function survey_responses() {
-  $survey = node_load(array('nid' => arg(1)));
+  $survey = node_load(arg(1));
   $response_id = arg(3);
 
   if ($response_id) {
     $response = db_fetch_object(db_query("SELECT * FROM {survey_responses} WHERE rid=%d", $response_id));
-    $content = form_item(t('submitted by'), format_name(user_load(array('uid' => $response->uid))));
-    $content.= form_item(t('date'), format_date($response->created));
+    $content = '<div>' . t('submitted by') . ' ' . theme('username', user_load(array('uid' => $response->uid)));
+    $content.= ' on ' . format_date($response->created).'</div>';
 
     $res = db_query("SELECT f.title, r.value FROM {survey_fields} r INNER JOIN {form_fields} f ON f.ffid=r.ffid WHERE r.rid=%d ORDER BY f.weight", $response->rid);
     while ($field = db_fetch_object($res)) {
-      $content.= form_item($field->title, $field->value);
+      $content.= '<div><strong>' . $field->title . ': </strong>' . $field->value . '</div>';
     }
   }
   else {
     $header = array(t('Submitted by'), t('Date'), '');
     $res = pager_query("SELECT u.uid, u.name, r.created, r.rid FROM {users} u INNER JOIN {survey_responses} r ON r.uid=u.uid WHERE r.nid=%d ORDER BY created DESC", 50, NULL, NULL, $survey->nid);
     while ($response = db_fetch_object($res)) {
-      $rows[] = array(format_name($response), format_date($response->created),
+      $rows[] = array(theme('username',$response), format_date($response->created),
                       l(t('view'), 'node/'.$survey->nid.'/responses/'.$response->rid));
     }
     if ($pager = theme('pager', NULL, 50, 0, tablesort_pager())) {
@@ -320,7 +361,7 @@ function survey_responses() {
 }
 
 function survey_excel() {
-  $survey = node_load(array('nid' => arg(1)));
+  $survey = node_load(arg(1));
   if (!$survey->nid) {
     drupal_not_found();
   }
