diff -urpN dependent-5/dependent.info dependent/dependent.info
--- dependent-5/dependent.info	2008-05-31 11:10:05.000000000 -0700
+++ dependent/dependent.info	2008-09-17 22:08:19.000000000 -0700
@@ -1,12 +1,6 @@
-; $Id: dependent.info,v 1.1 2008/03/07 09:42:10 levyofi Exp $
+; $Id: $
 name = Dependent
 description = Make CCK fields dependent of the values of other fields.
-dependencies = content
+dependencies[] = content
 package = CCK
-
-
-; Information added by drupal.org packaging script on 2008-05-31
-version = "5.x-1.4-beta"
-project = "dependent"
-datestamp = "1212257405"
-
+core = 6.x
\ No newline at end of file
diff -urpN dependent-5/dependent.install dependent/dependent.install
--- dependent-5/dependent.install	2008-05-31 11:02:25.000000000 -0700
+++ dependent/dependent.install	2008-09-21 14:18:51.000000000 -0700
@@ -1,27 +1,59 @@
 <?php
 // $Id: dependent.install,v 1.2 2008/05/31 18:02:25 levyofi Exp $
 
+/**
+ * Implementation of hook_schema().
+ */
+function dependent_schema() {
+  $schema['field_dependencies'] = array(
+      'fields' => array(
+           'parent_field_name' => array(
+             'type' => 'varchar',
+             'length' => '32',
+             'not null' => TRUE),
+           'child_field_name' => array(
+             'type' => 'varchar',
+             'length' => '32',
+             'not null' => TRUE),
+           'parent_node_type_name' => array(
+             'type' => 'varchar',
+             'length' => '32',
+             'not null' => TRUE),
+           'child_node_type_name' => array(
+             'type' => 'varchar',
+             'length' => '32',
+             'not null' => TRUE),
+           'option_text' => array(
+             'type' => 'varchar',
+             'length' => '255',
+             'not null' => FALSE),
+           'put_after_parent' => array(
+             'type' => 'int',
+             'size' => 'tiny',
+             'not null' => FALSE,
+             'default' => 0,
+             'disp-width' => '1'),
+           'is_required' => array(
+             'type' => 'int',
+             'size' => 'tiny',
+             'not null' => FALSE,
+             'default' => 0,
+             'disp-width' => '1')),
+      'primary key' => array('parent_field_name', 'child_field_name', 'parent_node_type_name', 'child_node_type_name'),
+  );
+  return $schema;
+}
+
+/**
+ * Implementation of hook_install().
+ */
 function dependent_install() {
-  switch ($GLOBALS['db_type']) {
-    case 'mysqli':
-    case 'mysql':
-    case 'pgsql':
-      db_query("CREATE TABLE if not exists {field_dependencies} (
-        parent_field_name varchar(32) NOT NULL,
-        child_field_name varchar(32) NOT NULL,
-        parent_node_type_name varchar(32) NOT NULL,
-        child_node_type_name varchar(32) NOT NULL,
-        option_text varchar(255),
-        put_after_parent boolean default 0,
-        is_required boolean default 0,
-        PRIMARY KEY(parent_field_name,child_field_name,parent_node_type_name,child_node_type_name)                                         
-      ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
-      break;
-       default:
-      break;
-  }
-}  
+  drupal_install_schema('dependent');
+}
 
+/**
+ * Implementation of hook_uninstall().
+ */
 function dependent_uninstall() {
-   db_query("DROP TABLE {field_dependencies}");
+  drupal_uninstall_schema('dependent');
 }
\ No newline at end of file
diff -urpN dependent-5/dependent.module dependent/dependent.module
--- dependent-5/dependent.module	2008-05-31 11:02:25.000000000 -0700
+++ dependent/dependent.module	2008-09-21 14:50:12.000000000 -0700
@@ -1,68 +1,83 @@
 <?php
-
+// $Id$
   /*
- * Implementation of hook_form_alter()
+ * Implementation of hook_form_alter().
  */
-function dependent_form_alter($form_id, &$form) {
-  
-  if ($form_id == '_content_admin_field') {
+function dependent_form_alter(&$form, &$form_state, $form_id) {
+  if ($form_id == 'content_field_edit_form' || $form_id == '_content_admin_field') {
       //need to add our form element to the form where field types are created/updated
-      
+
       //get the names of the related content type and the field type
-      $content_type = content_types($form['type_name']['#value']); 
-      $field_name=$form['field_name']['#value'];
-      
+      $content_type = content_types($form['type_name']['#value']);
+      $field_name = $form['field_name']['#value'];
+
       //fill the options list in which the field type can be dependent on
-      //for now - thr list is filled with single on/off checkboxed and 2+ radio choices from the same content type only      
-      $options=dependent_create_form_options(array('parent'=>$content_type['type'], 'child'=>$content_type['type']) ,$form, $field_name);
-      if ($options===FALSE){
+      //for now - thr list is filled with single on/off checkboxed and 2+ radio choices from the same content type only
+      $options = dependent_create_form_options(array(
+        'parent' => $content_type['type'],
+        'child' => $content_type['type']),
+        $form,
+        $field_name
+        );
+      if ($options === FALSE) {
         return $form;
-      }else{        
-        $form['#submit']['dependent_submition'] = array($options); //this is how we tell drupal that during submition the 'dependent_submition' function should be called               
-      } 
+      }
+      else{
+        //this is how we tell drupal that during submition the
+        // 'dependent_submition' function should be called
+        // $form['#submit']['dependent_submition'] = array($options);
+        $form['#submit'][] = 'dependent_submition';
+        $form['#dependant_submition_options'] = array($options);
+      }
   }
-  else if (strpos($form_id,'_node_form')){//this is a node form    
+  else if (strpos($form_id, '_node_form')) {//this is a node form
     $content_type = $form['type']['#value'];
-    $dependencies=db_query("SELECT * FROM {field_dependencies} WHERE parent_node_type_name='%s'", $content_type);
-    if (db_num_rows($dependencies)>0){
+    $dependencies = db_query("SELECT * FROM {field_dependencies} WHERE parent_node_type_name='%s'", $content_type);
+    $dependencies_switch = FALSE;
+    $form_dependencies = array();
+    while ($data = db_fetch_array($dependencies)) {
+      $dependencies_switch = TRUE;
+      $form_dependencies[] = $data;
+    }
+    if ($dependencies_switch > 0) {
       dependent_unset_required_before_validation($form_id, $form);
-      $form['#validate']['dependent_validate_required_fields']=array();
-    }     
-    while ($field=db_fetch_array($dependencies)){      //the while loop is to support future development where a field can be dependent on many parents
-      if (isset($form[$field['child_field_name']])){ 
-        if (isset($form[$field['child_field_name']]['#theme'])){
-          $form[$field['child_field_name']]['#prefix']='<div class="form-item">'.$form[$field['child_field_name']]['#prefix'];
-          $form[$field['child_field_name']]['#suffix'].=$form[$field['child_field_name']]['#suffix'].'</div>';
-        }                                                                                                           
-        $suffix=$form[$field['child_field_name']]['#suffix'].'<div class="child_of_'.$field['parent_field_name'].'" style="display: none">child of '.$field['parent_field_name'].($field['put_after_parent']?' put_after_parent':'').(($field['option_text']=='no_value_needed')?'':(' option_text='.$field['option_text'])).'</div>';//this string will help the javascript to hide/show this field
+      $form['#validate'][] = 'dependent_validate_required_fields';
+    }
+    foreach ($form_dependencies as $field) {      //the while loop is to support future development where a field can be dependent on many parents
+      if (isset($form[$field['child_field_name']])) {
+        if (isset($form[$field['child_field_name']]['#theme'])) {
+          $form[$field['child_field_name']]['#prefix'] = '<div class="form-item">'. $form[$field['child_field_name']]['#prefix'];
+          $form[$field['child_field_name']]['#suffix'] .= $form[$field['child_field_name']]['#suffix'] .'</div>';
+        }
+        $suffix = $form[$field['child_field_name']]['#suffix'] .'<div class="child_of_'. $field['parent_field_name'] .'" style="display: none">child of '. $field['parent_field_name'] . ($field['put_after_parent']? ' put_after_parent' : '') . (($field['option_text'] == 'no_value_needed')? '' :( ' option_text='. $field['option_text'])) .'</div>';//this string will help the javascript to hide/show this field
         $form[$field['child_field_name']]['#suffix']=$suffix;
       }
-      if ((isset($form[$field['parent_field_name']]))&&(strpos($form[$field['parent_field_name']]['#suffix'],"this_is_a_parent")===FALSE)){        
-        $suffix=$form[$field['parent_field_name']]['#suffix'].'<div class="this_is_a_parent" style="display: none">'.$field['parent_field_name'].(($field['option_text']=='no_value_needed')?'':(' parent_text='.$field['option_text'])).'</div>';
+      if ((isset($form[$field['parent_field_name']]))&&(strpos($form[$field['parent_field_name']]['#suffix'], "this_is_a_parent")===FALSE)) {
+        $suffix = $form[$field['parent_field_name']]['#suffix'] .'<div class="this_is_a_parent" style="display: none">'. $field['parent_field_name'] . (($field['option_text'] == 'no_value_needed')? '' : (' parent_text='. $field['option_text'])) .'</div>';
         //$suffix='<div class="this_is_a_parent" style="display: none">'.$field['parent_field_name'].(($field['option_text']=='no_value_needed')?'':(' parent_text='.$field['option_text'])).'</div>';
-        $form[$field['parent_field_name']]['#suffix']=$suffix;         
-      }            
-    } 
-    foreach ($form as $key=>$value){
-      if (strpos($key,'field')!==FALSE){//this is a field
-        if (isset($value['key']['#options'])){
+        $form[$field['parent_field_name']]['#suffix'] = $suffix;
+      }
+    }
+    foreach ($form as $key => $value) {
+      if (strpos($key, 'field')!==FALSE) {//this is a field
+        if (isset($value['key']['#options'])) {
           $index= array_search('N/A', $value['key']['#options']);
-          if ($index!==FALSE){ 
+          if ($index!==FALSE) {
             $len=strlen($index);
             $flag=($len==0);
-            if ($len==0){
+            if ($len==0) {
               unset($form[$key]['key']['#options'][$index]);
             }
           }
-        }                      
+        }
       }
     }
-    
+
     drupal_add_css(drupal_get_path('module', 'dependent') .'/dependent.css');
     drupal_add_js(drupal_get_path('module', 'dependent') .'/dependent.js');
   }
   else if ($form_id == '_content_admin_field_remove') { //a field removal page - need to update the database
-    $form['#submit']['dependent_content_admin_field_remove_submit'] = array();
+    $form['#submit'][] = 'dependent_content_admin_field_remove_submit';
   }
 }
 
@@ -70,157 +85,176 @@ function dependent_form_alter($form_id, 
 /*
  * this function is being called when the admin saves field settings
  * $options - an array with all the options that this field can depend on.
- */  
-function dependent_submition($form_id, $form_values, $options) {
-  if ($form_id == '_content_admin_field') {
-  //this is a submition of adding or editing a field type      
-    if (isset($form_values['dependent_options'])){
+ */
+function dependent_submition($form, &$form_state) {
+  $options = $form['#dependant_submition_options'];
+  if ($form['#id'] == 'content-field-edit-form') {
+  //this is a submition of adding or editing a field type
+    if (isset($options)) {
       //get the names of the content type and field type
-      $content_type = $form_values['type_name'];
-      $field_name=$form_values['field_name'];
-      
+      $content_type = $form_state['values']['type_name'];
+      $field_name=$form_state['values']['field_name'];
       //check if this is an update operation
-      $is_updatable=db_num_rows(db_query("SELECT * FROM {field_dependencies} WHERE child_field_name='%s' AND child_node_type_name='%s'", $field_name, $content_type));
-      
-      //get the selected choice 
-      $choice=strval($form_values['dependent_options']);
-      $option=explode(" option from ",$options[$choice]);
-      ($choice>0)?($selected_value=(count($option)>1)?$option[0]:'no_value_needed'):'';                         
+      $is_updatable = FALSE;
+      $is_updatable=db_result(db_query("SELECT COUNT(*) FROM {field_dependencies} WHERE child_field_name='%s' AND child_node_type_name='%s'", $field_name, $content_type));
+      //get the selected choice
+      $choice=strval($form_state['values']['dependent_options']);
+      $option=explode(" option from ", $options[0][$choice]);
+      ($choice>0)?($selected_value=(count($option)>1)?$option[0]:'no_value_needed'):'';
       ($choice>0)?$selected_field = ($option[1]?$option[1]:$options[$choice]): '';
-      
       //if this is an update delete previous database entries
-      if ($is_updatable){
-        db_query("DELETE FROM {field_dependencies} WHERE child_field_name='%s' AND child_node_type_name='%s'", $field_name, $content_type);            
-      }        
-      //enter the choice to the database 
-      ($choice>0)?db_query("INSERT INTO {field_dependencies} VALUES ('%s','%s','%s','%s','%s',%s, %s)",$selected_field, $field_name, $content_type, $content_type, $selected_value, $form_values['put_after_parent'], $form_values['required']):'';        
-    }   
+      if ($is_updatable) {
+        db_query("DELETE FROM {field_dependencies} WHERE child_field_name='%s' AND child_node_type_name='%s'", $field_name, $content_type);
+      }
+      //enter the choice to the database
+      ($choice>0)?db_query("INSERT INTO {field_dependencies} VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s')", $selected_field, $field_name, $content_type, $content_type, $selected_value, $form_state['put_after_parent'], $form_state['required']):'';
+    }
   }
 }
 
 /*
  * this function is being called when the admin removes a field
  * $options - an array with all the options that this field can depend on.
- */ 
-function dependent_content_admin_field_remove_submit($form_id, $form_values) {
-  $content_type = $form_values['type_name'];
-  $field_name=$form_values['field_name'];
-  if ( $content_type && $field_name && $form_values['confirm']) {//remove this field dependencies data frm database
-    db_query("DELETE FROM {field_dependencies} WHERE (child_field_name='%s' OR parent_field_name='%s') AND child_node_type_name='%s'", $field_name, $field_name, $content_type);            
+ */
+function dependent_content_admin_field_remove_submit($form, &$form_state) {
+  $content_type = $form_state['type_name'];
+  $field_name=$form_state['field_name'];
+  if ( $content_type && $field_name && $form_state['confirm']) {//remove this field dependencies data frm database
+    db_query("DELETE FROM {field_dependencies} WHERE (child_field_name='%s' OR parent_field_name='%s') AND child_node_type_name='%s'", $field_name, $field_name, $content_type);
   }
 }
 
 /*
- * Implementation of hook_form_alter()
+ * Implementation of hook_form_alter().
  */
 function dependent_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
-  switch($op) {
+  switch ($op) {
     case 'view'://hide the content of fields depends on the value of the parent field
       $nodecopy=$node;
       $result=db_query("SELECT * FROM {field_dependencies} WHERE child_node_type_name='%s'", $node->type);
-      while ($field=db_fetch_object($result)){
-         $value_needed=($field->option_text=='no_value_needed')?"1":$field->option_text;
-         $parent_field=$field->parent_field_name;
-         //check if $value_needed is in the array of $parent_field
-         $found=false;
-         $parent_content=$node->$parent_field;
-         for($index=0; $index<count($node->$parent_field); ++$index){           
-           if ($parent_content[$index]['value']==$value_needed){
-              $found=true;
-           }
-         }
-         if ((!isset($node->content[$parent_field]))||((!$found)&&(isset($node->content[$field->child_field_name])))){
-            unset($node->content[$field->child_field_name]);
-         }
+      while ($field=db_fetch_object($result)) {
+        $value_needed=($field->option_text=='no_value_needed')?"1":$field->option_text;
+        $parent_field=$field->parent_field_name;
+        //check if $value_needed is in the array of $parent_field
+        $found=FALSE;
+        $parent_content=$node->$parent_field;
+        for ($index=0; $index<count($node->$parent_field); ++$index) {
+          if ($parent_content[$index]['value']==$value_needed) {
+            $found=TRUE;
+          }
+        }
+        if ((!isset($node->content[$parent_field]))||((!$found)&&(isset($node->content[$field->child_field_name])))) {
+          unset($node->content[$field->child_field_name]);
+        }
       }
       return $node;
       break;
     case 'validate':
       $nodecopy=$node;
+      break;
   }
 }
 
 /*
  * This function return an array of options in which a field can be depends on. it also adds the nessecery form elements to the form
  * @param $content_types
- *   An array that represents the content types involved, with two keys 'parent' as the parent content type and 'child' as the dependent content type. 
- * 
+ *   An array that represents the content types involved, with two keys 'parent' as the parent content type and 'child' as the dependent content type.
+ *
  * @param $form
  *  The form to add the possible options that the admin should choose from
- * 
+ *
  * $param $field_name
- *  The field name that this setting is for. Use null if this field is from another content tyoe
- * 
+ *  The field name that this setting is for. Use null if this field is from another content type
+ *
  * @param $new_for_name
  *  The name of the fieldset item to add to $form
- * 
+ *
  * @param $weight
  *  The weight that the form item will get in the form
- * 
+ *
  * @param $form_value_name
- *  The initial for the form items in the fielset - this is useful when adding more than one fieldsets in other modules   
+ *  The initial for the form items in the fielset - this is useful when adding more than one fieldsets in other modules
  */
 
-function dependent_create_form_options($content_types, &$form, $field_name=NULL, $new_form_name='dependent', $weight=-5, $form_value_name=""){
-  if (isset($field_name)){
-    $onoff_field_instances=db_query('SELECT * FROM {node_field_instance} WHERE widget_type="options_onoff" and type_name="%s" and field_name<>"%s"', $content_types['parent'],$field_name );
-    $options_field_instances=db_query('SELECT nfi.field_name, nf.global_settings FROM {node_field_instance} nfi,{node_field} nf WHERE nfi.widget_type="options_buttons" and nfi.type_name="%s" and nfi.field_name=nf.field_name and nfi.field_name<>"%s"', $content_types['parent'], $field_name);      
-    $selection_field_instances=db_query('SELECT nfi.field_name, nf.global_settings FROM {node_field_instance} nfi,{node_field} nf WHERE nfi.widget_type="options_select" and nfi.type_name="%s" and nfi.field_name=nf.field_name and nfi.field_name<>"%s"', $content_types['parent'], $field_name);      
-  }else{
-    $onoff_field_instances=db_query('SELECT * FROM {node_field_instance} WHERE widget_type="options_onoff" and type_name="%s"', $content_types['parent']);
-    $options_field_instances=db_query('SELECT nfi.field_name, nf.global_settings FROM {node_field_instance} nfi,{node_field} nf WHERE nfi.widget_type="options_buttons" and nfi.type_name="%s" and nfi.field_name=nf.field_name', $content_types['parent']);       
-    $selection_field_instances=db_query('SELECT nfi.field_name, nf.global_settings FROM {node_field_instance} nfi,{node_field} nf WHERE nfi.widget_type="options_select" and nfi.type_name="%s" and nfi.field_name=nf.field_name', $content_types['parent']);       
+function dependent_create_form_options($content_types, &$form, $field_name=NULL, $new_form_name='dependent', $weight=-5, $form_value_name="") {
+  if (isset($field_name)) {
+    $onoff_field_instances=db_query('SELECT * FROM {content_node_field_instance} WHERE widget_type="optionwidgets_onoff" and type_name="%s" and field_name<>"%s"', $content_types['parent'], $field_name );
+    $options_field_instances=db_query('SELECT cnfi.field_name, cnf.global_settings FROM {content_node_field_instance} cnfi,{content_node_field} cnf WHERE cnfi.widget_type="optionwidgets_buttons" and cnfi.type_name="%s" and cnfi.field_name=cnf.field_name and cnfi.field_name<>"%s"', $content_types['parent'], $field_name);
+    $selection_field_instances=db_query('SELECT cnfi.field_name, cnf.global_settings FROM {content_node_field_instance} cnfi,{content_node_field} cnf WHERE cnfi.widget_type="optionwidgets_select" and cnfi.type_name="%s" and cnfi.field_name=cnf.field_name and cnfi.field_name<>"%s"', $content_types['parent'], $field_name);
+  }
+  else{
+    $onoff_field_instances=db_query('SELECT * FROM {content_node_field_instance} WHERE widget_type="optionwidgets_onoff" and type_name="%s"', $content_types['parent']);
+    $options_field_instances=db_query('SELECT cnfi.field_name, cnf.global_settings FROM {content_node_field_instance}  cnfi,{content_node_field} cnf WHERE cnfi.widget_type="optionwidgets_buttons" and cnfi.type_name="%s" and cnfi.field_name=cnf.field_name', $content_types['parent']);
+    $selection_field_instances=db_query('SELECT cnfi.field_name, cnf.global_settings FROM {content_node_field_instance} cnfi,{content_node_field} cnf WHERE cnfi.widget_type="optionwidgets_select" and cnfi.type_name="%s" and cnfi.field_name=cnf.field_name', $content_types['parent']);
   }
   $row=1;
-  if ((db_num_rows($onoff_field_instances)==0)&&(db_num_rows($options_field_instances)==0)&& (db_num_rows($selection_field_instances)==0)) //no field type can be selected  
+  $instance_switch = FALSE;
+  $onoff_instance = array();
+  $options_instance = array();
+  $selection_instance = array();
+  while ($data = db_fetch_object($onoff_field_instances)) {
+    $instance_switch = TRUE;
+    $onoff_instance[] = $data;
+  }
+  while ($data = db_fetch_object($options_field_instances)) {
+    $instance_switch = TRUE;
+    $options_instance[] = $data;
+  }
+  while ($data = db_fetch_object($selection_field_instances)) {
+    $instance_switch = TRUE;
+    $selection_instance[] = $data;
+  }
+
+  if ($instance_switch == FALSE) { //no field type can be selected
     return FALSE;
-  
-  //the first oprion is "no field"  
+  }
+  //the first option is "no field"
   $options[0]=t("no field");
   //add the single on/off checkboxes to the options array
-  while($onoff_field=db_fetch_object($onoff_field_instances)){
+  foreach ($onoff_instance as $onoff_field) {
       $options[$row++]="$onoff_field->field_name";// in $onoff_field->type_name";
   }
-  //add the options on each radio buttons field type. every single choice will be added as a separate choice which includes the choice text and the field type name     
-  while($options_field=db_fetch_object($options_field_instances)){
-      $field_details=content_fields($options_field->field_name,$content_types['parent']);
+  //add the options on each radio buttons field type. every single choice will be added as a separate choice which includes the choice text and the field type name
+  foreach ($options_instance as $options_field) {
+      $field_details=content_fields($options_field->field_name, $content_types['parent']);
       $field_options_array=explode("\r\n", $field_details['allowed_values']);
-      //iterate through the array and put the options in $options together with the field name          
-      foreach($field_options_array as $option){
-         $options[$row++]=$option.' '.t("option from").' '.$options_field->field_name;
-         //print_r($options);
-      }          
-  }
-  
-  //add the options on each radio buttons field type. every single choice will be added as a separate choice which includes the choice text and the field type name     
-  while($options_field=db_fetch_object($selection_field_instances)){
-      $field_details=content_fields($options_field->field_name,$content_types['parent']);
+      //iterate through the array and put the options in $options together with the field name
+      foreach ($field_options_array as $option) {
+        $options[$row++]=$option .' '. t("option from") .' '. $options_field->field_name;
+      }
+  }
+
+  //add the options on each radio buttons field type. every single choice will be added as a separate choice which includes the choice text and the field type name
+  foreach ($selection_instance as $options_field) {
+      $field_details=content_fields($options_field->field_name, $content_types['parent']);
       $field_options_array=explode("\r\n", $field_details['allowed_values']);
-      //iterate through the array and put the options in $options together with the field name          
-      foreach($field_options_array as $option){
-         $options[$row++]=$option.' '.t("option from").' '.$options_field->field_name;
-         //print_r($options);
-      }          
+      //iterate through the array and put the options in $options together with the field name
+      foreach ($field_options_array as $option) {
+        $options[$row++]=$option .' '. t("option from") .' '. $options_field->field_name;
+      }
   }
-  
   //if this is an update operation we need to load the previously selected valued to the options list
-  $prev_result=db_query('SELECT * FROM {field_dependencies} WHERE child_field_name="%s" AND parent_node_type_name="%s" AND child_node_type_name="%s"', isset($field_name)?$field_name:"related", $content_types['parent'],$content_types['child']);
-  $is_updatable=db_num_rows($prev_result);
+  $prev_result=db_query('SELECT * FROM {field_dependencies} WHERE child_field_name="%s" AND parent_node_type_name="%s" AND child_node_type_name="%s"', $field_name, $content_types['parent'], $content_types['child']);
+  $prev_result_count = 0;
+  $prev_result_array = array();
+  while ($data = db_fetch_object($prev_result)) {
+    $prev_result_count ++;
+    $prev_result_obj = $data;
+  }
+  $is_updatable=$prev_result_count;
   $prev_selected=array();
   $put_after_parent_flag=FALSE;
-  while ($parent = db_fetch_array($prev_result)){
-    $selected_item=(($parent['option_text']=='no_value_needed')?'':($parent['option_text'].' '.t("option from").' ')).$parent['parent_field_name'] ;
-    $prev_selected[]=array_search($selected_item,$options); 
-    $put_after_parent_flag=$parent['put_after_parent'];
-  }
-  
-  $form[$new_form_name] = array( 
+  $selected_item=(($prev_result_obj->option_text=='no_value_needed')?'':($prev_result_obj->option_text .' '. t("option from") .' ')) . $prev_result_obj->parent_field_name;
+  $prev_selected[]=array_search($selected_item, $options);
+  $put_after_parent_flag=$prev_result_obj->put_after_parent;
+
+  $form[$new_form_name] = array(
     '#type' => 'fieldset',
     '#title' => t('Dependent options'),
     '#weight' => $weight,
   );
-  
-  $form[$new_form_name][$form_value_name.'dependent_options'] = array(//the selection options for this field to depend on
+
+  $form[$new_form_name][$form_value_name .'dependent_options'] = array(//the selection options for this field to depend on
     '#type' => 'select',
     '#title' => t('Field instances'),
     '#default_value' => $is_updatable ? $prev_selected : array(0),
@@ -229,8 +263,8 @@ function dependent_create_form_options($
     '#size' => min(count($options), 6),
     '#description' => t('Choose the on/off checkbox field instances which the current field will depend on'),
   );
-  $form[$new_form_name][$form_value_name.'put_after_parent']=array( //a checkbox to determine is this field should appear after the parent field
-    '#type' =>'checkbox',
+  $form[$new_form_name][$form_value_name .'put_after_parent']=array( //a checkbox to determine is this field should appear after the parent field
+    '#type' => 'checkbox',
     '#title' => t('show this field right after its parent'),
     '#default_value' => $put_after_parent_flag,
     '#description' => t('check this option if you want this field to be shown right after the selected item'),
@@ -239,35 +273,34 @@ function dependent_create_form_options($
 }
 
 /*
- * This function look for dependent fields in the form and unset the required flag if exists   
+ * This function look for dependent fields in the form and unset the required flag if exists
  */
-function dependent_unset_required_before_validation($form_id, &$form){
-  $dependencies=db_query("SELECT * FROM {field_dependencies} WHERE parent_node_type_name='%s' AND is_required=1", $form['type']['#value']);    
-  while ($field=db_fetch_array($dependencies)){      
+function dependent_unset_required_before_validation($form_id, &$form) {
+  $dependencies=db_query("SELECT * FROM {field_dependencies} WHERE parent_node_type_name='%s' AND is_required=1", $form['type']['#value']);
+  while ($field=db_fetch_array($dependencies)) {
     //if (($form['#post'][$field['parent_field_name']]['key']!==$field['option_text'])||(($field['option_text']=='no_value_needed')&&($form_values[$field['paremt_field_name']]===0))){
-      dependent_find_and_destroy_required_flag($form[$field['child_field_name']], $field['child_field_name'] );
+      dependent_find_and_destroy_required_flag($form[$field['child_field_name']], $field['child_field_name']);
     //}
-  }  
+  }
 }
 
 /*
  * This function get a form element and find it required flag and unsets it. It also adds the html recognition flag of a required field so this field will still looks as required
  * This is done because the module validation functions are called after the default node_form_validate function
  */
-function dependent_find_and_destroy_required_flag(&$element, $field_name){
-  global $dependent_required_fields;  
-  if (!isset($dependent_required_fields)){
-    $dependent_required_fields=array();
+function dependent_find_and_destroy_required_flag(&$element, $field_name) {
+  global $_dependent_required_fields;
+  if (!isset($_dependent_required_fields)) {
+    $_dependent_required_fields=array();
   }
-  foreach ($element as $key=>$value) {
+  foreach ($element as $key => $value) {
     if (strval($key)=='#required') {
       unset($element[$key]);
-      $dependent_required_fields[]=$field_name;
-      $element['#title'].= '<span class="form-required" title="'. t('This field is required.') .'">*</span>';
-      
+      $_dependent_required_fields[]=$field_name;
+      $element['#title'] .= '<span class="form-required" title="'. t('This field is required.') .'">*</span>';
       return;
     }
-    if (is_array($value)){
+    if (is_array($value)) {
       dependent_find_and_destroy_required_flag($element[$key], $field_name);
     }
   }
@@ -278,16 +311,17 @@ function dependent_find_and_destroy_requ
  * it looks for the required fields that the function 'dependent_find_and_destroy_required_flag' have set as not required.
  * it then checks if this field was supposed to be filled. If yes, the function checks whether the field has a value and if not it calles 'form_set_error'
  */
-function dependent_validate_required_fields($form_id, $form_values){
-  $dependencies=db_query("SELECT * FROM {field_dependencies} WHERE parent_node_type_name='%s' AND is_required=1", $form_values['type']);    
-  while ($field=db_fetch_array($dependencies)){      
-    if (($form_values[$field['parent_field_name']]['key']===$field['option_text'])||(($field['option_text']=='no_value_needed')&&($form_values[$field['paremt_field_name']]===1))){//check if the parent field has the right value for the child field to be filled
-      if (((isset($form_values[$field['child_field_name']]['key']))&&($form_values[$field['child_field_name']]['key']===""))||((isset($form_values[$field['child_field_name']][0]))&&($form_values[$field['child_field_name']][0]['value']===""))){//check if the child field has a value
-      //the child field does not have a value
-          $field_data=content_fields($field['child_field_name'],$form_values['type']);
-          form_set_error('dependent',t('!name field is required.', array('!name' => $field_data['widget']['label'])));          
+function dependent_validate_required_fields($form_id, $form_values) {
+  $dependencies=db_query("SELECT * FROM {field_dependencies} WHERE parent_node_type_name='%s' AND is_required=1", $form_values['type']);
+  while ($field=db_fetch_array($dependencies)) {
+    if (($form_values[$field['parent_field_name']]['key']===$field['option_text'])||(($field['option_text']=='no_value_needed')&&($form_values[$field['paremt_field_name']]===1))) {
+      //check if the parent field has the right value for the child field to be filled
+      if (((isset($form_values[$field['child_field_name']]['key']))&&($form_values[$field['child_field_name']]['key']===""))||((isset($form_values[$field['child_field_name']][0]))&&($form_values[$field['child_field_name']][0]['value']===""))) {
+        //check if the child field has a value
+          //the child field does not have a value
+          $field_data=content_fields($field['child_field_name'], $form_values['type']);
+          form_set_error('dependent', t('!name field is required.', array('!name' => $field_data['widget']['label'])));
       }
     }
-  }    
-}
-?>
+  }
+}
\ No newline at end of file
