I'm creating an action to trigger on a rule when a user is logged in. I have a field of the user that is a term reference.
I would like to redirect to the url field of the chosen term. This is how I get the chosen url:
$tid = $user->field_redirect_field['und'][0]['tid'];
$taxonomy = taxonomy_term_load($tid);
$url = $taxonomy->field_url['und'][0]['safe_value'];
I receive a perfect url like stocklijst/gezocht (this works ok). Now I would like to redirect to that url. I've tried this:
drupal_goto($url);
But it doesn't redirect. It always goes to the front-page...
UPDATE:
This is what I do now:
I have a rule (When user logged in) that triggers a custom action "Redirect to user url". It's a custom action like this:
function redirectonlogin_rules_action_info() {
$actions = array(
'redirectonlogin_redirect_login' => array(
'label' => t('Redirect on login'),
'group' => t('My custom actions'),
'parameter' => array(
// curent user
'user' => array(
'type' => 'user',
'label' => t('User'),
'description' => t('The current logged in user.'),
'save' => FALSE,
),
),
),
);
return $actions;
}
function redirectonlogin_redirect_login($user) {
// REDIRECT TO USER REDIRECT FIELD
$tid = $user->field_redirect_field['und'][0]['tid'];
$taxonomy = taxonomy_term_load($tid);
$url = $taxonomy->field_url['und'][0]['safe_value'];
unset($_GET['destination']);
drupal_static_reset('drupal_get_destination');
drupal_goto($url);
}
The user can select a url in a select list. These are taxonomy terms... .
This works perfectly. But it takes some time, could there be a cleaner way and faster way of doing this?