Index: forms.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/forms/forms.module,v
retrieving revision 1.15
diff -u -F^f -r1.15 forms.module
--- forms.module	29 Nov 2005 19:12:04 -0000	1.15
+++ forms.module	24 Jun 2006 06:29:34 -0000
@@ -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,160 @@ 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, 
+    '#options' => _forms_get_field_types($exclude), 
+  );
+  $form['weight'] = array(
+    '#type' => 'weight', 
+    '#title' => t('Weight'), 
+    '#default_value' =>  $field->weight, 
+    '#DANGEROUS_SKIP_CHECK' => TRUE, 
+    '#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,
+  );
+  $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) {
