我正在使用 drupal 表单,我创建了一个多步骤表单,允许用户在 3 个页面或 3 个界面之间导航。一旦用户在 page2 中填写了所需的表单,submitt 函数必须在一个数组中收集这些信息,然后将此数组传递给要在此页面中使用的下一页。我正在寻找一种将 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;
}
这是我的功能,一切正常,但我只想将数据数组传递给下一个表单,最好的解决方案是什么。