--- invite.module.orig	2005-12-23 08:06:24.000000000 -0500
+++ invite.module	2006-01-22 19:19:45.000000000 -0500
@@ -69,43 +69,65 @@
   }
 
   // configure settings for the new members
-  $group = form_select(t('Target role'), 'invite_target_role', 
-            variable_get('invite_target_role', '3'), 
-            ($target_roles ? $target_roles : array('-1'=>t('(Please add a target role.)'))), 
-            t('Choose the role that invited users will be added to. For example, <i>Member</i>.'));
-  
-  $group .= form_select(t('Invitation Expiry'), 'invite_expiry', 
-            variable_get('invite_expiry', 30), 
-            drupal_map_assoc(array(5, 10, 15, 20, 25, 30, 45, 60)), 
-            t('Set the expiry period for user invitations, in days'), 
-            $extra = 0, $multiple = FALSE, $required = TRUE);
-
-  $group .= form_select(t('Number of invitations per user'), 'invite_maxnum', 
-            variable_get('invite_maxnum', 10), 
-            drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20)), 
-            t('Maximum number of invitations a user may send'), 
-            $extra = 0, $multiple = FALSE, $required = TRUE);
+  $form['usersettings'] = array('#type' => 'fieldset', '#title' => t('User settings'), '#weight' => -8);
+
 
-  $output = form_group(t('User settings'),$group);
+  $form['usersettings']['invite_target_role'] = array(
+    '#type' => 'select', 
+    '#title' => t('Target role'), 
+    '#default_value' => variable_get('invite_target_role', '3'), 
+    '#options' => ($target_roles ? $target_roles : array('-1'=>t('(Please add a target role.)'))), 
+    '#weight' => -99, 
+    '#description' => t('Choose the role that invited users will be added to. For example, <i>Member</i>.'));
+
+  $form['usersettings']['invite_expiry'] = array(
+    '#type' => 'select', 
+    '#title' => t('Invitation Expiry'), 
+    '#default_value' => variable_get('invite_expiry', 30), 
+    '#options' => drupal_map_assoc(array(5, 10, 15, 20, 25, 30, 45, 60)), 
+    '#weight' => -98, 
+    '#required' => TRUE,
+    '#description' => t('Set the expiry period for user invitations, in days'));
+
+  $form['usersettings']['invite_maxnum'] = array(
+    '#type' => 'select', 
+    '#title' => t('Number of invitations per user'), 
+    '#default_value' => variable_get('invite_maxnum', 10), 
+    '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20)), 
+    '#weight' => -97, 
+    '#required' => TRUE,
+    '#description' => t('Maximum number of invitations a user may send'));
 
   // configure settings for the email 
-   $group = form_textfield(t('Subject'), 'invite_subject', 
-                           variable_get('invite_subject',t("You've been invited")), 20, 64, 
-                           t('Type the subject of the invitation email'), 
-                           $attributes = NULL, $required = FALSE);
+  $form['emailsettings'] = array('#type' => 'fieldset', '#title' => t('Email settings'), '#weight' => -6, '#collapsible' => TRUE, '#collapsed' => FALSE);
+
+  $form['emailsettings']['invite_subject'] = array(
+    '#type' => 'textfield', 
+    '#title' => t('Subject'), 
+    '#size' => 20, 
+    '#maxlength' => 64,
+    '#default_value' => variable_get('invite_subject',t("You've been invited")), 
+    '#weight' => -99, 
+    '#description' => t('Type the subject of the invitation email'));
+
 
   if (module_exist("feature")){
-    $group .= form_checkbox(t('Include Features'), 'invite_include_features',
-               $value = 1,
-               $checked = variable_get('invite_include_features', '0'), 
-               $description = t('Include the Features module output as part of the email'),
-               $attributes = NULL, $required = FALSE);
+    $form['emailsettings']['invite_include_features'] = array(
+      '#type' => 'checkbox', 
+      '#title' => t('Include Features'), 
+      '#return_value' => 1, 
+      '#default_value' => variable_get('invite_include_features', '0'), 
+      '#weight' => -99, 
+      '#description' => t('Include the Features module output as part of the email'));
   
   }
-  $output .= form_group(t('Email settings'),$group);
-  $output .= form_group(t('Sample Email'),_invite_send_invite('display'));
+  $form['emailsettings']['emailsample'] = array('#type' => 'fieldset', '#title' => t('Sample Email'), '#weight' => -5, '#collapsible' => TRUE, '#collapsed' => TRUE);
+  $form['emailsettings']['emailsample']['sample'] = array(
+    '#type' => 'markup', 
+    '#value' => '<div class="emailpreview">' . _invite_send_invite('display') . '</div>');
+
 
-  return $output;
+  return $form;
 }
 
 /*
@@ -139,7 +161,7 @@
 *         insert - on successful insert, the user status is set active and the role is escalated
 */
 
-function invite_user($type, &$edit, &$user, $category = NULL) {
+function invite_user($type, &$edit, &$user) {
 
     // What type of registration action are we taking?
     switch ($type) {
@@ -149,7 +171,8 @@
            _invite_check_msgs($user->uid);
            if ($type == t("view") && ($user->uid == $GLOBALS['user']->uid)){
              $data = l("Invite a friend",'invite');
-             return array("Buddy List" => $data);
+            $form['Buddy List'] = array('#value' => $data);
+            return $form;
            }
         }
         break;
@@ -157,13 +180,24 @@
 
         // Add items to the registration form.
 
-        $output .= form_textfield('Registration Code', 'invite_code', '', 30, 64, 'If you are signing up because you received an invitation email, type the registration code found near the bottom of the email.', $attributes = NULL, $required = FALSE);
-        $output .= form_textfield('Email', 'invite_email', '', 30, 64, 'Enter the email address where you received your invitation. ', $attributes = NULL, $required = FALSE);
+        $form['regcodes'] = array('#type' => 'fieldset', '#title' => t('Registration Code'), '#weight' => 10, '#collapsible' => TRUE, '#collapsed' => FALSE);
+        $form['regcodes']['invite_code'] = array(
+          '#type' => 'textfield', 
+          '#title' => t('Registration Code'), 
+          '#size' => 30, 
+          '#maxlength' => 64,
+          '#default_value' => '', 
+          '#description' => t('If you are signing up because you received an invitation email, type the registration code found near the bottom of the email.'));
+
+        $form['regcodes']['invite_email'] = array(
+          '#type' => 'textfield', 
+          '#title' => t('Email'), 
+          '#size' => 30, 
+          '#maxlength' => 64,
+          '#default_value' => '', 
+          '#description' => t('Enter the email address where you received your invitation.'));
 
-        return array(
-                array('title' => t('Registration Code'),
-                      'data' => $output,
-                      'weight' => -1));
+        return $form;
       case t("validate"):
         // The user has filled out the form and checked the "accept" box.
         if (($edit["invite_code"]) && !($edit["invite_email"])) {
@@ -283,17 +317,32 @@
       $invites_left = variable_get('invite_maxnum',10) - $inc;
       $group .= "<br />You have ".$invites_left." invites left<br />";
       $headers=array("Email","Status","");
-      $output .= form_group("Your invitations",$group);
+      $form['yourinvites'] = array('#type' => 'fieldset', '#title' => t('Your invitations'), '#weight' => 5, '#collapsible' => TRUE, '#collapsed' => FALSE);
+      $form['yourinvites']['invitelist'] = array(
+        '#type' => 'markup', 
+        '#value' => '<div class="invitelist">' . $group . '</div>');
       
       //the invitation form
+      $form['inviteform'] = array('#type' => 'fieldset', '#title' => t('Invite a friend'), '#weight' => 5, '#collapsible' => TRUE, '#collapsed' => FALSE);
       if ($inc < variable_get('invite_maxnum',10)){
-        $form = form_textfield("Email", "email", "", 20, 64, "Type the email of the person you would like to invite", $attributes = NULL, $required = TRUE) ;
-        $form .= form_submit("submit");
+        $form['inviteform']['email'] = array(
+          '#type' => 'textfield', 
+          '#title' => t('Email'), 
+          '#size' => 20, 
+          '#maxlength' => 64,
+          '#default_value' => '', 
+          '#required' => TRUE, 
+          '#description' => t('Type the email of the person you would like to invite.'));
+        $form['inviteform']['op'] = array(
+          '#type' => 'submit', 
+          '#value' => t('submit'), 
+          '#weight' => 23); 
       } else {
-        $form .= 'Maximum number of invitations reached';
+        $form['inviteform']['invitemaxed'] = array(
+          '#type' => 'markup', 
+          '#value' => '<div class="inviteform">Maximum number of invitations reached</div>');
       }
-      $group = form_group("Invite a friend",$form);
-      $output .= form($group);
+      $output .= drupal_get_form('invite_form', $form);
       print theme('page',$output);
     } 
 
