Hi,

I'm trying to port a module (called Evaluation) from drupal 4.7.x to drupal 5.x an I have some problems to get the forms work correctly.
The following code shows one of my forms and it's validation:

// Build the whole form with all elements
function evaluation_admin_roles_or_user_form() {
  $form = array();
  $form['#pre_render'] = array('evaluation_pre_render'); // set the pre_render function
  $form['users'] = evaluation_select_user(); // the input field
  // ...
  // build the whole form with all elements
  // ...
  return $form;
}

// create the input field for the username
function evaluation_select_user() {
  $form = array(
    '#type' => 'textfield',
    '#title' => t('Select user'),
    '#maxlength' => 60,
    '#autocomplete_path' => 'evaluation/autocomplete',
    '#description' => t('The user to which the selected questions should be assigned.'),
    );
  return $form;
}

 // callback for the hook_menu()
function evaluation_admin_roles_or_user() {
  drupal_set_title(t('Assign questions'));
  // The $_GET variable is always empty 
  return drupal_get_form('evaluation_admin_roles_or_user_form', $form); 
  }
}

function evaluation_pre_render($form_id, &$form, $next_page = TRUE) {
  global $form_values;

  // ****************************************
  // form_values is always empty here!
  // **************************************** 

  // switch for different forms
  switch ($form_id) {
    case 'evaluation_admin_roles_or_user_form':
      // $_POST and $_GET['page'] is always empty
      if ((isset($_POST['op']) || isset($_GET['page']))) {
         // do something...
        }
      break;
      // ... more code ... 
  }

function evaluation_form_alter($form_id, &$form) {
  switch ($form_id) {
    case 'evaluation_admin_roles_or_user_form':
      $form['page'] = array(
        '#type' => 'hidden',
        '#value' => isset($_POST['edit']['page']) ? $_POST['edit']['page'] : 1,
        );
      if ($_POST['op'] == t('Back')) {
        $form['page']['#value']--;
      }
      evaluation_pre_render($form_id, $form, FALSE);
      $form['#validate'] = array_merge((array)$form['#validate'], 
        array(
          'evaluation_select_user_validate' => array(),
          ));
      $form['#submit'] = array_merge((array)$form['#submit'], 
        array(
          'evaluation_assign_single_submit' => array(),
          'evaluation_assign_random_submit' => array(),
          'evaluation_assign_all_submit' => array(),
          ));
      break;
     // ... more code ... // 
  }
}
// validation function
function evaluation_select_user_validate($form_id, $form_values) {
    // *********************************
    // form_values['users'] contains the username 
   // ***********************************
}

My Problem is, that the $form_values['users'] is only filled with the username I write in the textfield ('Select User') in the "evaluation_select_user_validate" function. In "evaluation_pre_render" the $_form_values variable is always empty. The $_POST and $_GET variables are also always empty, but I think this is may caused by the same issue as the problem with the $form_values variable.

Has anybody an idea what could be the problem?

Greetings

sauron

Comments

killes@www.drop.org’s picture

This is due to changes in form API from 4.7 to 5.0. I had to jump through a lot of hoops to get the wizard like forms to work in evaluation 4.7. The whole pre_render stuff probably needs to be completely rewritten and can hopefully be simplified a lot.

--
Drupal services
My Drupal services

sauron-1’s picture

Hi,
I know there's a new API, and I red the Guide to port modules from 4.7.x to 5.x but I didn't find something about what I described. I just want to make the module run as soon as possible and then I have enough time to port it the right 5.x way. I tried to set the $_GET/$_POST and the $form_values variables hard-coded directly in the code in the pre_render function and it seems to work (only for my hard coded input), so is there any possibility to get access to these variables in 5.x?

Greetings