0

I've being trying to write custom module that redirects user from user register page after submit. I read several issues on Drupal Offsite and here on Stackexchange, but could not still resolve the issue.

This is my custom module code:

function myregistration_form_user_register_form_alter(&$form,&$form_state){
  unset($_GET['destination']);
  drupal_static_reset('drupal_get_destination');
  $_GET['destination'] = array('query'=>array('q'=>'order_translaton'));
}

The URL of the page I want to redirect to is: http://www.sociofobic.ru/drupal/?q=order_translaton.

After registering user no redirect occurs. Instead I get the NOTICE:

Notice: Array to string conversion in url_is_external() (line 2312 of /home/bnqpdcme/public_html/drupal/includes/common.inc). Notice: Array to string conversion in drupal_parse_url() (line 589 of /home/bnqpdcme/public_html/drupal/includes/common.inc). and Page not found: The requested page "/drupal/?q=Array" could not be found.

Please tell me what I do wrong, because the syntax for URL redirection I use is the same as explained in drupal_redirect_form().

2

The syntax that you use is not the same as in the API docs. The qis to much.

Also, you shouldn't manipulate $_GET, that's not at all reliable. The correct way to achieve what you want, is to add a custom form submit handler and when that is called to set $form_state['redirect'].

Have a look at the accepted answer to this question: https://stackoverflow.com/questions/14542975/drupal-7-redirect-to-a-specific-page-a-tab-after-form-submit

| improve this answer | |
  • Thanks, it helped! I am new to Drupal. I though that q is key and 'order_translaton' is value. I just wrote $form_state['redirect']= 'order_translaton'; and it worked. – user2490392 Jan 31 '14 at 21:50
0

Redirecting form after user save is easy

add a hook_form_alter()

$form['#submit'][1] = 'callback_redirect_to_custom_url_you_want';

function callback_redirect_to_custom_url_you_want(&$form, &$form_state){
    //get the custom field you want to redirect (sample code given below)
    $_GET['destination'] = array('query'=>array('q'=>'order_translaton'));
    $clean = $_GET['destination'] ;
    // or create a custom url you want to redirect 
            $custom_url = $form_state['values']['field_name']['und'][0]['value'];
            $path = isset($custom_url) && !empty($custom_url) ? $custom_url : "";
            $clean = strtolower(trim($path, '-'));
            $form_state['redirect'] = $clean;
        }
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.