--- quotes_old.module	2005-02-27 03:19:13.000000000 +0000
+++ quotes.module	2006-03-26 13:12:37.000000000 +0100
@@ -156,4 +156,11 @@
 
 /**
+ * Implementation of hook_node_info().
+ */
+function quotes_node_info() {
+  return array('quotes' => array('name' => t('quote'), 'base' => 'quotes'));
+}
+
+/**
  * Implementation of hook_node_name().
  */
@@ -182,18 +189,44 @@
  */
 function quotes_form(&$io_node) {
-  $the_output = '';
-
-  if (function_exists('taxonomy_node_form')) {
-    $the_output .= implode('', taxonomy_node_form('quotes', $io_node));
-  }
+  $form['title'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Title'),
+    '#default_value' => $io_node->title,
+    '#size' => 60,
+    '#maxlength' => 128,
+    '#description' => NULL,
+    '#attributes' => NULL,
+    '#required' => TRUE,
+  );
 
   if (user_access('promote quotes to block')) {
-    $the_output .= form_checkbox(t('Display in quote blocks'), 'quotes_promote', 1, (isset($io_node->quotes_promote) ? $io_node->quotes_promote : 1));
+    $form['quotes_promote'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Display in quote blocks'),
+      '#return_value' => 1,
+      '#default_value' => (isset($io_node->quotes_promote) ? $io_node->quotes_promote : 1),
+    );
   }
 
   switch (arg(3)) {
     case 'import':
-      $the_output .= form_radios(t('Format'), 'quotes_format', ($io_node->quotes_format ? $io_node->quotes_format : 'text'), array('text' => t('Tab-separated text'), 'fortune' => t('Fortune file')), NULL, TRUE);
-      $the_output .= form_textarea(t('Quotes'), 'body', $io_node->body, 60, 20, NULL, NULL, TRUE);
+      $form['quotes_format'] = array(
+        '#type' => 'radios',
+        '#title' => t('Format'),
+        '#default_value' => ($io_node->quotes_format ? $io_node->quotes_format : 'text'),
+        '#options' => array('text' => t('Tab-separated text'), 'fortune' => t('Fortune file')),
+        '#description' => NULL,
+        '#required' => TRUE,
+      );
+      $form['body'] = array(
+        '#type' => 'textarea',
+        '#title' => t('Quotes'),
+        '#default_value' => $io_node->body,
+        '#cols' => 60,
+        '#rows' => 20,
+        '#description' => NULL,
+        '#attributes' => NULL,
+        '#required' => TRUE,
+      );
       break;
 
@@ -208,17 +241,45 @@
       }
 
-      $the_output .= form_hidden('quotes_format', 'text');
-      $the_output .= form_textarea(t('Quotes'), 'body', $io_node->body, 60, 20, NULL, NULL, TRUE);
+      $form['quotes_format'] = array(
+        '#type' => 'hidden',
+        '#value' => 'text',
+      );
+      $form['body'] = array(
+        '#type' => 'textarea',
+        '#title' => t('Quotes'),
+        '#default_value' => $io_node->body,
+        '#cols' => 60,
+        '#rows' => 20,
+        '#description' => NULL,
+        '#attributes' => NULL,
+        '#required' => TRUE,
+      );
       break;
 
     default:
-      $the_output .= form_textarea(t('Quote'), 'body', $io_node->body, 60, 7, NULL, NULL, TRUE);
-      $the_output .= form_textarea(t('Author'), 'quotes_author', $io_node->quotes_author, 60, 3);
+      $form['body'] = array(
+        '#type' => 'textarea',
+        '#title' => t('Quote'),
+        '#default_value' => $io_node->body,
+        '#cols' => 60,
+        '#rows' => 7,
+        '#description' => NULL,
+        '#attributes' => NULL,
+        '#required' => TRUE,
+      );
+      $form['quotes_author'] = array(
+        '#type' => 'textarea',
+        '#title' => t('Author'),
+        '#default_value' => $io_node->quotes_author,
+        '#cols' => 60,
+        '#rows' => 3,
+      );
       break;
   }
+  
+  $form['format'] = filter_form($io_node->format);
+  
+  return $form; 
 
-  $the_output .= filter_form('format', $io_node->format);
-
-  return $the_output;
 } // function quotes_form
 
@@ -398,8 +459,15 @@
 function quotes_user($in_type, &$io_edit, &$io_user) {
   if (($in_type == 'view') && user_access('edit own quotes', $io_user)) {
-    return array(t('History') => form_item(t('Quotes'), l(t("view %user's quotes", array('%user' => $io_user->name)), "quotes/$io_user->uid", array('title' => t("View %username's quotes.", array('%username' => $io_user->name))))));
+    $form['quotes'] = array(
+      '#type' => 'item',
+      '#title' => t('Quotes'),
+      '#value' => l(t("view %user's quotes", array('%user' => $io_user->name)), "quotes/$io_user->uid", array('title' => t("View %username's quotes.", array('%username' => $io_user->name))))
+    );
+    
+    return array(t('History') => $form);
   }
 } // function quotes_user
 
+
 /**
  * Implementation of hook_block().
@@ -604,6 +672,6 @@
  */
 function theme_quotes_quote($in_node) {
-  $in_node->body = check_output($in_node->body, $in_node->format);
-  $the_author = ($in_node->quotes_author ? check_output(variable_get('quotes_leader', '&mdash;') . ' ' . $in_node->quotes_author, $in_node->format) : '');
+  $in_node->body = check_markup($in_node->body, $in_node->format);
+  $the_author = ($in_node->quotes_author ? check_markup(variable_get('quotes_leader', '&mdash;') . ' ' . $in_node->quotes_author, $in_node->format) : '');
 
   return "
@@ -631,12 +699,12 @@
  */
 function theme_quotes_page($in_uid) {
-  $the_edit = $_POST['edit'];
   $the_sort_options = array('n.created' => t('creation date'), 'n.title' => t('title'), 'q.author' => t('author'));
   $the_order_options = array('ASC' => t('ascending'), 'DESC' => t('descending'));
   $the_limit_options = array(variable_get('default_nodes_main', 10) => variable_get('default_nodes_main', 10), 10 => 10, 25 => 25, 50 => 50, 75 => 75, 100 => 100);
 
-  $the_sort = (array_key_exists($the_edit['quotes_page_sort'], $the_sort_options) ? $the_edit['quotes_page_sort'] : 'n.created');
-  $the_order = (array_key_exists($the_edit['quotes_page_order'], $the_order_options) ? $the_edit['quotes_page_order'] : 'DESC');
-  $the_limit = (array_key_exists($the_edit['quotes_page_limit'], $the_limit_options) ? $the_edit['quotes_page_limit'] : variable_get('default_nodes_main', 10));
+  $the_sort = (array_key_exists($_GET['sort'], $the_sort_options) ? $_GET['sort'] : 'n.created');
+  $the_order = (array_key_exists($_GET['order'], $the_order_options) ? $_GET['order'] : 'DESC');
+  $the_limit_default = variable_get('default_nodes_main', 10);
+  $the_limit = (array_key_exists($_GET['limit'], $the_limit_options) ? $_GET['limit'] : $the_limit_default);
 
   if ($in_uid) {
@@ -657,21 +725,60 @@
     $the_result = pager_query(db_rewrite_sql("SELECT DISTINCT(n.nid), n.sticky, n.created, n.title, q.author FROM {node} n INNER JOIN {quotes} q ON q.nid = n.nid WHERE n.type = 'quotes' AND n.status = 1 ORDER BY n.sticky DESC, $the_sort $the_order"), $the_limit);
   }
-
-  $the_form = t('Sort by: ');
-  $the_form .= form_select(NULL, 'quotes_page_sort', $the_sort, $the_sort_options);
-  $the_form .= form_select(NULL, 'quotes_page_order', $the_order, $the_order_options);
-  $the_form .= t('Quotes per page: ');
-  $the_form .= form_select(NULL, 'quotes_page_limit', $_POST['edit']['quotes_page_limit'], $the_limit_options);
-  $the_form .= form_submit(t('Go'), NULL);
-
-  $the_output = form_item(t('Display options'), form($the_form, 'post', NULL, array('class' => 'container-inline')));
+  
+  $the_form .= theme_select(array(
+    '#name'=> 'sort',
+    '#title' => t('Sort by'),
+    '#value' => $the_sort,
+    '#options' => $the_sort_options,
+    '#parents' => array(''), //fixes form_set_error when not using forms API
+  ));
+  $the_form .= theme_select(array(
+    '#name'=> 'order',
+    '#title' => t('Ordering'),
+    '#value' => $the_order,
+    '#options' => $the_order_options,
+    '#parents' => array(''),
+  ));
+   $the_form .= theme_select(array(
+    '#name'=> 'limit',
+    '#title' => t('Quotes per page'),
+    '#value' => $the_limit,
+    '#options' => $the_limit_options,
+    '#parents' => array(''),
+  ));
+  $the_form .= theme_button(array(
+    '#value' => 'Go',
+    '#parents' => array(''),
+  ));
+  
+  $the_form = theme_fieldset(array(
+      '#title' => "Display options",
+      //'#description'
+      '#children' => $the_form,
+      '#collapsible'=> TRUE,
+      '#collapsed'=> TRUE,
+      '#parents' => array(''),
+    )
+  );
+  
+  $the_output .= theme_form(array(
+    '#action' => url($_GET['q']),
+    '#method' => 'GET',
+    '#children' => $the_form,
+    '#parents' => '',
+  ));
 
   while ($the_node = db_fetch_object($the_result)) {
     $the_output .= node_view(node_load(array('nid' => $the_node->nid)), 1);
   }
-
-  $the_output .= theme('pager', NULL, $the_limit);
+  
+  $options = array();
+  if (isset($_GET['sort']) && $_GET['sort'] != 'n.created') $options['sort'] = $the_sort;
+  if (isset($_GET['order']) && $_GET['order'] != 'DESC') $options['order'] = $the_order;
+  if (isset($_GET['limit']) && $_GET['limit'] != $the_limit_default) $options['limit'] = $the_limit;
+  
+  $the_output .= theme('pager', NULL, $the_limit, 0, $options);
   $the_output .= theme('xml_icon', $the_url);
-
+  
   drupal_set_html_head("<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS - $the_title\" href=\"$the_url\" />");
 
@@ -679,4 +786,5 @@
 } // function theme_quotes_page
 
+
 /********************************************************************
  * Module Functions
@@ -804,5 +912,5 @@
    * purposes.
    */
-  return array('text' => '4.6r1', 'build' => 2005022601);
+  return array('text' => '4.7r1', 'build' => 2006032301);
 } // function quotes_version
 
@@ -861,5 +969,5 @@
 
   $the_user = ($in_uid ? user_load(array('uid' => $in_uid, 'status' => 1)) : $user);
-  $the_result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.teaser, n.created, u.name, u.uid FROM {node} n INNER JOIN {users} u ON u.uid = n.uid WHERE n.type = 'quotes' AND u.uid = %d AND n.status = 1 ORDER BY n.created DESC"), $the_user->uid, 0, 15);
+  $the_result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, r.body, n.created, u.name, u.uid FROM {node} n INNER JOIN {users} u ON u.uid = n.uid INNER JOIN {node_revisions} r ON n.vid = r.vid WHERE n.type = 'quotes' AND u.uid = %d AND n.status = 1 ORDER BY n.created DESC"), $the_user->uid, 0, 15);
   node_feed($the_result, array('title' => t("%user's quotes", array('%user' => $the_user->name)), 'link' => url("quotes/$the_user->uid", NULL, NULL, TRUE)));
 } // function _quotes_feed_user
@@ -869,5 +977,5 @@
  */
 function _quotes_feed_last() {
-  $the_result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.teaser, n.created, u.name, u.uid FROM {node} n INNER JOIN {users} u ON u.uid = n.uid WHERE n.type = 'quotes' AND n.status = 1 ORDER BY n.created DESC"), 0, 15);
+  $the_result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, r.body, n.created, u.name, u.uid FROM {node} n INNER JOIN {users} u ON u.uid = n.uid INNER JOIN {node_revisions} r ON n.vid = r.vid WHERE n.type = 'quotes' AND n.status = 1 ORDER BY n.created DESC"), 0, 15);
   node_feed($the_result, array('title' => variable_get('site_name', 'drupal') . ' ' . t('quotes'), 'link' => url("quotes", NULL, NULL, TRUE)));
 } // function _quotes_feed_last
@@ -920,4 +1028,8 @@
 } // function _quotes_parse_import
 
+function theme_quotes_admin_status ($title, $status) {
+  return '<div><b>' . $title . '</b>: '. $status . '</div>';
+}
+
 /**
  * Displays an overview of the module status.
@@ -942,23 +1054,42 @@
     if ($the_cur_ver) {
       $the_output = t('<p>The quotes module must be upgraded to continue.  Press <em>Upgrade</em> to create the new database tables and import your existing quotes.</p>');
-      $the_output .= form(form_submit(t('Upgrade')));
+      $form['upgrade'] = array(
+        '#type' => 'submit',
+        '#value' => t('Upgrade')
+      );
+      return drupal_get_form('quotes_admin_upgrade', $form);
     }
     else {
       $the_output = t('<p>The quotes module must be installed to continue.  Press <em>Install</em> to proceed</p>');
-      $the_output .= form(form_submit(t('Install')));
+      $form['install'] = array(
+        '#type' => 'submit',
+        '#value' => t('Install')
+      );
+      return drupal_get_form('quotes_admin_install', $form);
     }
-
-    print theme('page', $the_output);
-    return;
   }
 
-  $the_form = form_item(t('Status'), t('Installed'));
-  $the_form .= form_item(t('Version'), $the_cur_ver['text']);
-  $the_form .= form_item(t('Quotes'), db_result(db_query("SELECT COUNT(*) FROM {node} n where type = 'quotes'")));
-  $the_form .= form_textfield(t('Author leader'), 'quotes_leader', variable_get('quotes_leader', '&mdash;'), 32, 32, t('The text placed before the author attribution (i.e. "&amp;mdash;" for an em-dash or "&amp;#8226;" for a bullet).'));
-  $the_form .= form_submit(t('Submit'));
-  $the_output = form($the_form);
-
-  print theme('page', $the_output);
+  $form['quotes_status'] = array(
+    '#value' => theme_quotes_admin_status(t('Status'), t('Installed')),
+  );
+  $form['quotes_version'] = array(
+    '#value' => theme_quotes_admin_status(t('Version'), $the_cur_ver['text'])
+  );  
+  $form['quotes_quotes'] = array(
+    '#value' => theme_quotes_admin_status(t('Quotes'), db_result(db_query("SELECT COUNT(*) FROM {node} n where type = 'quotes'"))),
+  );  
+  $form['quotes_leader'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Author leader'),
+    '#default_value' => variable_get('quotes_leader', '&mdash;'),
+    '#size' => 32,
+    '#maxlength' => 32,
+    '#description' => t('The text placed before the author attribution (i.e. "&amp;mdash;" for an em-dash or "&amp;#8226;" for a bullet).'),
+  );
+  $form['quotes_submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Submit')
+  );
+  return drupal_get_form('quotes_admin', $form);
 } //function _quotes_admin_overview
 
@@ -967,18 +1098,4 @@
  */
 function _quotes_blocks() {
-  if ($_POST['op'] == t('Save')) {
-    foreach ($_POST['edit']['blocks'] as $the_bid => $the_block) {
-      if (!$the_block['name']) {
-        form_set_error("blocks][$the_bid][name", t('Please enter a name'));
-        continue;
-      }
-
-      db_query("UPDATE {quotes_blocks} SET name = '%s', title = '%s' WHERE bid = %d", $the_block['name'], $the_block['title'], $the_bid);
-    }
-
-    drupal_set_message(t('Blocks successfully updated.'));
-  }
-
-  $the_header = array(array('data' => t('Name'), 'field' => 'name'), array('data' => t('Title'), 'field' => 'title'), t('Filters'), array('data' => t('Operations'), 'colspan' => 2));
   $the_result = db_query('SELECT qb.* FROM {quotes_blocks} qb ' . tablesort_sql($the_header));
   $the_rows = array();
@@ -1002,15 +1119,17 @@
       $the_filters[] = t('term');
     }
-
-    $the_rows[] = array(
-      form_textfield(NULL, "blocks][$the_block->bid][name", $the_block->name, 16, 255),
-      form_textfield(NULL, "blocks][$the_block->bid][title", $the_block->title, 16, 255),
+    
+    $rows[] = array(
+      $the_block->name,
+      $the_block->title,
       implode(', ', (count($the_filters) ? $the_filters : array(t('none')))),
-      l(t('configure'), "admin/quotes/edit/$the_block->bid"),
-      l(t('delete'), "admin/quotes/delete/$the_block->bid"));
+      l(t('edit'), "admin/quotes/edit/$the_block->bid"),
+      '#value' => l(t('delete'), "admin/quotes/delete/$the_block->bid")
+    );
   }
 
-  if (count($the_rows)) {
-    $the_output .= form(theme('table', $the_header, $the_rows) . form_submit(t('Save')));
+  if (count($rows)) {
+    $the_header = array(array('data' => t('Name'), 'field' => 'name'), array('data' => t('Title'), 'field' => 'title'), t('Filters'), array('data' => t('Operations'), 'colspan' => 2));
+    $the_output  = '<div>' . theme('table', $the_header, $rows) . '</div>';   
   }
   else {
@@ -1018,61 +1137,70 @@
   }
 
-  print theme('page', $the_output);
+  return $the_output;
 } // function _quotes_blocks
 
-/**
- * Displays a form for adding or editing a quote block.
- */
-function _quotes_blocks_form($in_bid = 0) {
-  if ($_POST['op'] == t('Submit')) {
-    $the_name = trim($_POST['edit']['name']);
-    $the_title = trim($_POST['edit']['title']);
-    $the_type = (($_POST['edit']['type'] == 1) ? 1 : 0);
-    $the_nids = trim($_POST['edit']['nid_filter']);
-    $the_rids = ($_POST['edit']['rid_filter'] ? implode(',', $_POST['edit']['rid_filter']) : '');
-    $the_uids = ($_POST['edit']['uid_filter'] ? implode(',', $_POST['edit']['uid_filter']) : '');
-    $the_tids = ($_POST['edit']['tid_filter'] ? implode(',', $_POST['edit']['tid_filter']) : '');
-
-    if (!$the_name) {
-      form_set_error('name', t('Please enter a block name.'));
-    }
-
-    if ($the_nids) {
-      if (!preg_match('<^(?:\d+\W+)*\d+$>', $the_nids, $the_nids)) {
-        form_set_error('nid_filter', t('Please enter valid node IDs.'));
-      }
-      else {
-        $the_nids = preg_replace('<\W+>', ',', $the_nids[0]);
-      }
-    }
 
-    if (!form_get_errors()) {
-      if ($in_bid) {
-        if (db_query("UPDATE {quotes_blocks} SET name = '%s', title = '%s', block_type = %d, nid_filter = '%s', rid_filter = '%s', uid_filter = '%s', tid_filter = '%s' WHERE bid = %d", $the_name, $the_title, $the_type, $the_nids, $the_rids, $the_uids, $the_tids, $in_bid)) {
-          drupal_set_message(t('Block <em>%name</em> successfully updated.', array('%name' => $the_name)));
-          drupal_goto("admin/quotes/blocks");
-        }
-        else {
-          drupal_set_message(t('Block <em>%name</em> could not be updated.', array('%name' => $the_name)), 'error');
-        }
-      }
-      else {
-        $the_id = db_next_id('{quotes}_bid');
 
-        if (db_query("INSERT INTO {quotes_blocks} (bid, name, title, block_type, nid_filter, rid_filter, uid_filter, tid_filter) VALUES (%d, '%s', '%s', %d, '%s', '%s', '%s', '%s')", $the_id, $the_name, $the_title, $the_type, $the_nids, $the_rids, $the_uids, $the_tids)) {
-          drupal_set_message(t('Block <em>%name</em> successfully created.', array('%name' => $the_name)));
-          drupal_goto("admin/quotes/blocks");
-        }
-        else {
-          drupal_set_message(t('Block <em>%name</em> could not be created.', array('%name' => $the_name)), 'error');
-        }
-      }
+function quotes_blocks_form_validate($form_id, $form_values) {
+  $the_name = trim($form_values['name']);
+  $the_nids = trim($form_values['nid_filter']);
+  if (!$the_name) {
+    form_set_error('name', t('Please enter a block name.'));
+  }
+
+  if ($the_nids) {
+    if (!preg_match('<^(?:\d+\W+)*\d+$>', $the_nids, $the_nids)) {
+      form_set_error('nid_filter', t('Please enter valid node IDs.'));
+    }
+  }
+} // function _quotes_blocks_validate
+
+function quotes_blocks_form_submit($form_id, $form_values) {
+  $in_bid = arg(3);
+  $the_name = trim($form_values['name']);
+  $the_title = trim($form_values['title']);
+  $the_type = (($form_values['type'] == 1) ? 1 : 0);
+  $the_nids = trim($form_values['nid_filter']);
+  $the_rids = ($form_values['rid_filter'] ? implode(',', $form_values['rid_filter']) : '');
+  $the_uids = ($form_values['uid_filter'] ? implode(',', $form_values['uid_filter']) : '');
+  $the_tids = ($form_values['tid_filter'] ? implode(',', $form_values['tid_filter']) : '');
+  
+  //this should have been validated already
+  preg_match('<^(?:\d+\W+)*\d+$>', $the_nids, $the_nids);
+  $the_nids = preg_replace('<\W+>', ',', $the_nids[0]);
+
+  if ($in_bid) {
+    if (db_query("UPDATE {quotes_blocks} SET name = '%s', title = '%s', block_type = %d, nid_filter = '%s', rid_filter = '%s', uid_filter = '%s', tid_filter = '%s' WHERE bid = %d", $the_name, $the_title, $the_type, $the_nids, $the_rids, $the_uids, $the_tids, $in_bid)) {
+      drupal_set_message(t('Block <em>%name</em> successfully updated.', array('%name' => $the_name)));
+      drupal_goto("admin/quotes/blocks");
+    }
+    else {
+      drupal_set_message(t('Block <em>%name</em> could not be updated.', array('%name' => $the_name)), 'error');
     }
   }
-  elseif ($in_bid) {
-    $_POST['edit'] = db_fetch_array(db_query("SELECT qb.* FROM {quotes_blocks} qb WHERE bid = %d", $in_bid));
-    $_POST['edit']['rid_filter'] = explode(',', $_POST['edit']['rid_filter']);
-    $_POST['edit']['uid_filter'] = explode(',', $_POST['edit']['uid_filter']);
-    $_POST['edit']['tid_filter'] = explode(',', $_POST['edit']['tid_filter']);
+  else {
+    $the_id = db_next_id('{quotes}_bid');
+
+    if (db_query("INSERT INTO {quotes_blocks} (bid, name, title, block_type, nid_filter, rid_filter, uid_filter, tid_filter) VALUES (%d, '%s', '%s', %d, '%s', '%s', '%s', '%s')", $the_id, $the_name, $the_title, $the_type, $the_nids, $the_rids, $the_uids, $the_tids)) {
+      drupal_set_message(t('Block <em>%name</em> successfully created.', array('%name' => $the_name)));
+      drupal_goto("admin/quotes/blocks");
+    }
+    else {
+      drupal_set_message(t('Block <em>%name</em> could not be created.', array('%name' => $the_name)), 'error');
+    }
+  }
+} // function _quotes_blocks_submit
+
+
+
+/**
+ * Displays a form for adding or editing a quote block.
+ */
+function _quotes_blocks_form($in_bid = 0) {
+  if ($in_bid) {
+    $editvals = db_fetch_array(db_query("SELECT qb.* FROM {quotes_blocks} qb WHERE bid = %d", $in_bid));
+    $editvals['rid_filter'] = explode(',', $editvals['rid_filter']);
+    $editvals['uid_filter'] = explode(',', $editvals['uid_filter']);
+    $editvals['tid_filter'] = explode(',', $editvals['tid_filter']);
   }
 
@@ -1088,21 +1216,74 @@
   }
 
-  $the_form = form_textfield(t('Name'), 'name', $_POST['edit']['name'], 40, 255, t('Enter a unique name for this block. This will identify the block on the %link.', array('%link' => l('block administration page', 'admin/block'))), NULL, TRUE);
-  $the_form .= form_textfield(t('Block title'), 'title', $_POST['edit']['title'], 40, 255, t('Enter the title that will be used for this block when displayed. If desired, you can include the string <em>%title</em> which will be replaced by the title of the quote being displayed in the block.'));
-  $the_form .= form_radios(t('Type'), 'type', ($_POST['edit']['type'] ? $_POST['edit']['type'] : 0), array(t('Random'), t('Most recent')), NULL, TRUE);
-  $the_form .= form_textarea(t('Node filter'), 'nid_filter', $_POST['edit']['nid_filter'], 40, 4, t('To restrict this block to display only certain quotes based on node IDs, enter the IDs here separated by commas, spaces, or returns.'));
+  $form['name'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Name'),
+    '#default_value' => $editvals['name'],
+    '#size' => 40,
+    '#maxlength' => 255,
+    '#description' => t('Enter a unique name for this block. This will identify the block on the %link.', array('%link' => l('block administration page', 'admin/block'))),
+    '#required' => TRUE,
+  );
+  $form['title'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Block title'),
+    '#default_value' => $editvals['title'],
+    '#size' => 40,
+    '#maxlength' => 255,
+    '#description' => t('Enter the title that will be used for this block when displayed. If desired, you can include the string <em>%title</em> which will be replaced by the title of the quote being displayed in the block.'),
+  );
+  $form['type'] = array(
+    '#type' => 'radios',
+    '#title' => t('Type'),
+    '##default_value' => ($editvals['type'] ? $editvals['type'] : 0),
+    '#options' => array(t('Random'), t('Most recent')),
+    '#description' => NULL,
+    '#required' => TRUE,
+  );
+  $form['nid_filter'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Node filter'),
+    '#default_value' => $editvals['nid_filter'],
+    '#cols' => 40,
+    '#rows' => 4,
+    '#description' => t('To restrict this block to display only certain quotes based on node IDs, enter the IDs here separated by commas, spaces, or returns.'),
+  );
 
   if (count($the_roles)) {
-    $the_form .= form_select(t('Role filter'), 'rid_filter', $_POST['edit']['rid_filter'], $the_roles, t('To restrict this block to display only quotes submitted by users in specific roles, select the roles here.'), NULL, TRUE);
+    $form['rid_filter'] = array(
+      '#type' => 'select',
+      '#title' => t('Role filter'),
+      '##default_value' => $editvals['rid_filter'],
+      '#options' => $the_roles,
+      '#description' => t('To restrict this block to display only quotes submitted by users in specific roles, select the roles here.'),
+      '#extra' => NULL,
+      '#multiple' => TRUE,
+    );
   }
   else {
-    $the_form .= form_item(t('Role filter'), t('There are no roles configured with the <em>edit own quotes</em> permission, so no roles are available. To filter by role, please assign this permission to at least one role on the %link.', array('%link' => l(t('permission administration page'), 'admin/access'))));
+    $form[] = array(
+      '#type' => 'item',
+      '#title' => t('Role filter'),
+      '#default_value' => t('There are no roles configured with the <em>edit own quotes</em> permission, so no roles are available. To filter by role, please assign this permission to at least one role on the %link.', array('%link' => l(t('permission administration page'), 'admin/access'))),
+    );
   }
 
   if (count($the_users)) {
-    $the_form .= form_select(t('User filter'), 'uid_filter', $_POST['edit']['uid_filter'], $the_users, t('To restrict this block to display only quotes submitted by specific users, select the users here.'), NULL, TRUE);
+    $form['uid_filter'] = array(
+      '#type' => 'select',
+      '#title' => t('User filter'),
+      '##default_value' => $editvals['uid_filter'],
+      '#options' => $the_users,
+      '#description' => t('To restrict this block to display only quotes submitted by specific users, select the users here.'),
+      '#extra' => NULL,
+      '#multiple' => TRUE,
+    );
   }
   else {
-    $the_form .= form_item(t('User filter'), t('There are no users with the <em>edit own quotes</em> permission, so no users are available. To filter by user, please assign at least one user to a role with this permission on the %link.', array('%link' => l(t('user administration page'), 'admin/user'))));
+    $form['user_filter'] = array(
+      '#type' => 'item',
+      '#title' => t('User filter'),
+      '#value' => t('There are no users with the <em>edit own quotes</em> permission, so no users are available. To filter by user, please assign at least one user to a role with this permission on the %link.', array('%link' => l(t('user administration page'), 'admin/user'))),
+    );
   }
 
@@ -1114,20 +1295,31 @@
     while ($the_voc = db_fetch_object($the_result)) {
       $the_voc = taxonomy_get_vocabulary($the_voc->vid);
-      $the_group .= _taxonomy_term_select($the_voc->name, 'tid_filter', $_POST['edit']['tid_filter'], $the_voc->vid, $the_voc->help, TRUE, FALSE);
+      $the_group .= _taxonomy_term_select($the_voc->name, 'tid_filter', $editvals['tid_filter'], $the_voc->vid, $the_voc->help, TRUE, FALSE);
     }
 
     if ($the_group) {
-      $the_form .= form_group(t('Category filter'), $the_group, t('To restrict this block to display only quotes in specific categories, select the categories here.'));
+      $form['category_filter'] = array(
+        '#type' => 'fieldset',
+        '#title' => t('Category filter'),
+        '#description' => t('To restrict this block to display only quotes in specific categories, select the categories here.'),
+      );
     }
     else {
-      $the_form .= form_item(t('Category filter'), t('There are no vocabularies assigned to quotes. To filter by categories, please assign at least one vocabulary to quotes on the %link.', array('%link' => l(t('category administration page'), 'admin/taxonomy'))));
+      $form[] = array(
+        '#type' => 'item',
+        '#title' => t('Category filter'),
+        '#default_value' => t('There are no vocabularies assigned to quotes. To filter by categories, please assign at least one vocabulary to quotes on the %link.', array('%link' => l(t('category administration page'), 'admin/taxonomy'))),
+      );
     }
   }
+  
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Submit')
+  );
+  
+  $the_output .= drupal_get_form('quotes_blocks_form', $form);
 
-  $the_form .= form_submit(t('Submit'));
-
-  $the_output .= form($the_form);
-
-  print theme('page', $the_output);
+  return $the_output;
 } // function _quotes_blocks_form
 
@@ -1135,17 +1327,32 @@
  * Confirms and deletes a quote block.
  */
-function _quotes_blocks_delete($in_bid) {
+function _quotes_blocks_delete() {
+  $in_bid = arg(3);
   $the_block = db_fetch_object(db_query('SELECT qb.name FROM {quotes_blocks} qb WHERE qb.bid = %d', $in_bid));
-
-  if ($_POST['op'] == t('Delete')) {
-    db_query("DELETE FROM {quotes_blocks} WHERE bid = %d", $in_bid);
-    drupal_set_message(t('Block <em>%name</em> deleted.', array('%name' => $the_block->name)));
-    drupal_goto('admin/quotes/blocks');
-  }
-
   $the_output = t('<p>Are you sure you want to delete the block <em>%name</em>?', array('%name' => $the_block->name));
-  $the_output .= form(form_submit(t('Delete')));
+  
+  if (!$the_block)
+    return t('<p>Block id <em>%id</em> does not exist.', array('%id' => $in_bid));
+  
+  
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Submit')
+  );
+  
+  $the_output .= drupal_get_form('quotes_blocks_delete', $form);
 
-  print theme('page', $the_output);
+  return $the_output;
 } // function _quotes_blocks_delete
+
+function quotes_blocks_delete_submit($form_id, $form_values) {
+  $in_bid = arg(3);
+  
+  $the_block = db_fetch_object(db_query('SELECT qb.name FROM {quotes_blocks} qb WHERE qb.bid = %d', $in_bid));
+  
+  db_query("DELETE FROM {quotes_blocks} WHERE bid = %d", $in_bid);
+  drupal_set_message(t('Block <em>%name</em> deleted.', array('%name' => $the_block->name)));
+  drupal_goto('admin/quotes/blocks');
+}
+
 ?>
