--- C:/Documents and Settings/jimmy/®à­±/captcha.module	Tue Jun 19 09:00:22 2007
+++ C:/Documents and Settings/jimmy/®à­±/captcha_new.module	Sat Jun 23 16:46:56 2007
@@ -1,5 +1,5 @@
 <?php
-// $Id: captcha.module,v 1.41 2007/06/19 01:00:22 wundo Exp $
+// $Id: captcha.module,v 1.40 2007/05/09 16:49:42 wundo Exp $
 
 /**
  * Implementation of hook_help(). 
@@ -193,10 +193,14 @@
   $result = module_invoke($challenge[0], 'captcha', 'generate', $challenge[1]);
   
   $form = array_merge($form,$result['form']);
+  $validate_ary = array('captcha_validate' => array());
+  if(is_array($form['#validate'])){
+    $form['#validate'] = array_merge($form['#validate'], $validate_ary);
+  }
+  else{
+    $form['#validate'] = $validate_ary;
   
-  if(!isset($form['#validate']))
-    $form['#validate'] = array();
-  $form['#validate'] += array('captcha_validate' => array());
+  }
   $form['#pre_render'] = array('captcha_prerender');
 
   $_SESSION['captcha'][$seed]['success'] = FALSE;
@@ -206,6 +210,7 @@
   $_SESSION['captcha'][$seed]['preprocess'] = isset($result['preprocess'])? $result['preprocess'] : FALSE;
   $_SESSION['captcha'][$seed]['module'] = $challenge[0];
   $_SESSION['captcha'][$seed]['type'] = $challenge[1];
+  $_SESSION['captcha'][$seed]['value'] = $_SESSION['captcha'][$seed]['value'] ? $_SESSION['captcha'][$seed]['value'] : $result['value'];
 }
 
 function captcha_validate($form_id, $form_item) {
@@ -262,7 +267,7 @@
           '#type' => 'textfield',
           '#title' => t('Math Question: What is %problem?', array('%problem' => $x .' + '. $y)),
           '#description' => t('Please solve the math problem above and type in the result. e.g. for 1+1, type 2.'),
-          '#weight' => 0,
+          '#weight' => 5,
           '#required' => TRUE,
         );
       }
