Index: forms/forms.module
===================================================================
--- forms/forms.module	(revision 246)
+++ forms/forms.module	(revision 248)
@@ -86,7 +86,7 @@
  */
 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,160 @@
  * 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, 
+    '#options' => _forms_get_field_types($exclude), 
+  );
+  $form['weight'] = array(
+    '#type' => 'weight', 
+    '#title' => t('Weight'), 
+    '#default_value' =>  $field->weight, 
+    '#options' => _forms_get_field_types($exclude), 
+    '#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,
+    '#DANGEROUS_SKIP_CHECK' => 1, // Allows weight to pass validation.
+  );
+  $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) {
Index: survey/survey.module
===================================================================
--- survey/survey.module	(revision 246)
+++ survey/survey.module	(revision 248)
@@ -28,10 +28,10 @@
 }
 
 /**
- * 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'));
 }
 
 /**
@@ -50,7 +50,7 @@
     $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);
   }
@@ -122,32 +122,56 @@
  */
 function survey_form(&$node) {
   $output = '';
-  
+  /* not sure what to do with this
   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."));
-
-  $output .= form_hidden('fid', $node->fid);
-
-  return $output;
+  }*/
+  $form['title'] = array('#type' => 'textfield',
+    '#title' => t('Subject'),
+    '#default_value' => $node->title,
+    '#size' => 60,
+    '#maxlength' => 128,
+    '#required' => TRUE);
+  $form['body'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Intro Text'),
+    '#default_value' => $node->body,
+    '#cols' => 60,
+    '#rows' => 5,
+  );
+  $form["result_page"] = array(
+    '#type' => 'textfield',
+    '#title' => t('Path for "thank you" page'),
+    '#default_value' => $node->result_page,
+    '#size' => 70,
+    '#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(
+    '#type' => 'textfield',
+    '#title' => t('Email address'),
+    '#default_value' => $node->email,
+    '#size' => 70,
+    '#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,
+  );
+  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 +206,7 @@
  */
 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 +227,6 @@
   $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 +235,53 @@
   }
 
   $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');
-  }
 
-  $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;
+  $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'),
+  );
+  
+  return drupal_get_form('survey_fields_delete', $form);
 }
 
-function survey_submit() {
+/**
+ * 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_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");
@@ -294,19 +331,19 @@
 
   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(l($response->name, 'user/'. $response->uid, array('title' => t('View user profile.'))), format_date($response->created),
                       l(t('view'), 'node/'.$survey->nid.'/responses/'.$response->rid));
     }
     if ($pager = theme('pager', NULL, 50, 0, tablesort_pager())) {
