Drupal7 :以多步骤形式从一个接口提交数据到另一个接口


Drupal7 :submitt data in a multistep form from an interface to an another

我正在使用drupal表单,我创建了一个多步骤表单,允许用户在3个页面或3个界面之间导航。一旦用户在 page2 中填写了所需的表单,提交函数必须在一个数组中收集此信息,并将此数组传递到要在此页面中使用的下一页。我正在寻找一种从提交功能将 page2 的数据提交到下一页的正确方法

  function my_module_form_submit($form, &$form_state) {
  $data = array(); //array of data that takes data from the current page forms
  switch ($form_state['stage']) { // stage have 3 values(3 id) corresponding to three interfaces of forms
    case 'page1':
      // some simples instructions
     break;
      case 'page2':
         //collect data from page2 forms
         $database_name =$form_state['values']['databasename'];
         $user_name =$form_state['values']['username'];
         $user_pass =$form_state['values']['userpass'];
         $host =$form_state['values']['host'];
         $port =$form_state['values']['port'];
         $database_driver =$form_state['values']['databasedriver'];
         $db_array = array(); // put the data in an array
         $db_array['database'] = $database_name;
         $db_array['username'] = $user_name;
         $db_array['password'] = $user_pass; 
         $db_array['host'] = $host; //localhost
         $db_array['port'] = $port; //localhost
         $db_array['driver'] = $database_driver; //mysql
         // some query after being connected to the database that return an array containing 
         // existing data tables names in the current database(works fine) data tables names are stored in the array $data
     $form_state['multistep_values'][$form_state['stage']] = $form_state['values'];
     $form_state['new_stage'] = my_module_move_to_next_stage($form,$form_state);
     // function that changes the id of current the page to go to the next page: forms
   break;
  case 'page3':
  // some instructions
  break;
  $form_state['multistep_values']['form_build_id'] = $form_state['values']['form_build_id'];
  $form_state['stage'] = $form_state['new_stage']; //change the id of the current page and rebuilt the form with the next page forms
  $form_state['rebuild'] = TRUE;
}

这是我的函数,一切正常,但我只想将数据数组传递给下一个形式,最好的解决方案是什么。

我自己找到了解决方案:D要存储来自接口的数据并在另一个接口中使用它,我们可以这样做:在提交函数中,我们必须重建表单以移动到新界面,然后将数据存储在新表单中

  // submitt the first form
  $form_state['rebuild'] = TRUE; // rebuilt to go to the next form
  $form_state['storage']['myvalue'] =$data; // store the required data

在下一个表单中,我们要使用提交的数据,我们执行下一个表单。

function MY_MODULE_form($form, &$form_state) { // the next form
if (!empty($form_state['storage']['myvalue'])) { // call and use the submitted data
    $values=$form_state['storage']['myvalue'];
    //use the submitted data of the previous form in the new form
  }
 $form['new form'] = array(
    '#type' => 'radios',
    '#options' =>$values,
    );

  return $form;
}