自定义提交处理程序的重定向

时间:2014-04-02 08:56:21

标签: drupal-7 form-submit hook-form-alter

所以基本上这是我在这个问题上的第二天。

我有我的模块send_xml.module

function send_xml_form_user_register_form_alter(&$form, &$form_state) {
    $form['#submit'][] = 'send_xml_submit_function';
}

function send_xml_submit_function($form, &$form_state){
    $email = $form_state['values']['mail'];
    $password = $form_state['values']['pass'];
    $form_state['redirect'] = array(
        'mylink', array(
             'query' => array(
                  'email' => $email,
                  'password' => $password,
              ),
             ),
            );

但它在mylink中的流程后没有重定向,只是刷新页面。

2 个答案:

答案 0 :(得分:0)

像这样使用hook_form_alter

function send_xml_form_alter(&$form, &$form_state, $form_id) {
    switch ($form_id) {
        case 'user_register_form':
            $form['#submit'] = array('send_xml_submit_function');
            break;

        default:
            # code...
            break;
    }
}

function send_xml_submit_function($form, &$form_state){
    // call default submit -- this is default submit action for register form
    user_register_submit($form, $form_state);
    // if you use profile2 to create fields in register form then call this function too
    profile2_form_submit_handler($form, $form_state);


    $email = $form_state['values']['mail'];
    $password = $form_state['values']['pass'];
    $form_state['redirect'] = array(
      'mylink', array(
         'query' => array(
              'email' => $email,
              'password' => $password,
          ),
         ),
        );
}

几个星期前我遇到了同样的问题,这是我解决的问题,实际上我并不清楚为什么这项工作以及为什么追加#submit不起作用。
我检查了drupal user_register_submit代码,看起来很清楚$form_state['redirect']将用户重定向到<front>

答案 1 :(得分:0)

您还可以使用drupal_goto功能:

function send_xml_submit_function($form, &$form_state){
  $email = $form_state['values']['mail'];
  $password = $form_state['values']['pass'];

  drupal_goto('REDIRECT_pATH', array('query' => array('email' => $email, 'password' => $password)));
}