0

我是drupal的新手,需要创建一个我已经成功完成的登录表单。但是当我登录时,我希望表单切换到另一个表单,您可以在其中编辑您的详细信息。

我无法找出如何在表格之间切换。

<?php

/**
 * Implements hook_help.
 *
 * Displays help and module information.
 *
 * @param path 
 *   Which path of the site we're using to display help
 * @param arg 
 *   Array that holds the current path as returned from arg() function
 */

function login_kms_help($path, $arg) {
  switch ($path) {
    case "admin/help#login":
      return '<p>'.  t("Creates login module") .'</p>';
      break;
  }
} 

/**
 * Implements hook_block_info().
 */
function login_kms_block_info() {
   $blocks['login_kms'] = array(
    'info' => t('Login KMS'), //The name that will appear in the block list.
    'cache' => DRUPAL_CACHE_PER_ROLE, //Default
  );
  return $blocks;
}

function login_kms_block_view($delta = '') {
  $block = array();
  if($delta == 'login_kms') {
    $block['subject'] = 'Login';
    $block['content'] = drupal_render(drupal_get_form('login_kms_form_mode0'));
  } else if($delta == 'login_kms'){
    $block['subject'] = 'Edit';
    $block['content'] = drupal_render(drupal_get_form('login_kms_form_mode1'));
  }
  return $block;
}

function login_kms_form_mode0() {
  $form['username'] = array(
    '#type' => 'textfield',
    '#title' => t('Username:'),
  );
   $form['password'] = array(
    '#type' => 'password',
    '#title' => t('Password:'),
  );
  $form['Log in'] = array(
    '#type' => 'submit',
    '#value' => t('Log in'),
  );
  return $form;
}

function login_kms_form_mode1(){
  $form['username'] = array(
    '#type' => 'textfield',
    '#title' => t('mode1'),
  );
}

function login_kms_form_submit($form, &$form_state) {
    $mysql_user = $form_state['values']['username'];
    $mysql_pass = $form_state['values']['password'];
//  drupal_set_message(t($mysql_pass)); 
// some logic

}  
4

2 回答 2

1

第一种方法是使用 drupal_goto("my_path")。第二个也是更“正确”的方法是使用 $form_state['redirect'] 或 $form['#redirect'],就像这样;

function login_kms_form_submit($form, &$form_state) {
$mysql_user = $form_state['values']['username'];
$mysql_pass = $form_state['values']['password'];
//  drupal_set_message(t($mysql_pass)); 
// some logic
$form_state['redirect'] = 'user/to_the_new_form';

}

于 2013-11-03T06:14:56.040 回答
0

您可以简单地使用drupal_goto () 将登录的用户重定向到另一个表单。

global $user;
if(!empty($user->uid) || $user->uid > 0)
{
    drupal_goto("my/new/page");
}

希望这行得通……穆罕默德。

于 2012-07-05T07:18:48.110 回答