Redirect to a page
Last modified: June 5, 2009 - 03:42
Drupal 5.7
Works on a drupal 5.7 install with action.module v.1.
Drupal 5.x: Old action Style is deprecated in favour of action.module v.2, which includes this action by default.
Drupal 4.7.x
This is a simple action to redirect a user.
This might be useful, if you need to redirect someone to a special destination page, after he/she has created a special node type.
Oh, and the code is in an early state. There is no validation, if the given path or alias exists.
Any ideas are welcome.
<?php
function action_redirect_help($section) {
$output = '';
switch ($section) {
case 'admin/modules#description':
$output .= t('<strong>Action:</strong> Configurable page redirection for use in workflows.');
break;
}
return $output;
}
function action_redirect($op, $edit = array(), &$node) {
switch ($op) {
case 'metadata' :
return array (
'description' => t('Redirect user to a page'),
'type' => t('Redirect'),
'batchable' => false,
'configurable' => true);
case 'do' :
if(!isset($edit['destination'])){
// log
watchdog('error', t('Action Redirect: no redirect destination availbale!'));
break;
}
// get the path
$destination = $edit['destination'];
// log
watchdog('action', t('Redirecting to %destination', array('%destination' => $destination)));
drupal_goto($destination);
// If the above causes problems try
// $_REQUEST['destination'] = $destination;
break;
// return an HTML config form for the action
case 'form' :
// default values for form
$form = array ();
$form['destination'] = array (
'#type' => 'textfield',
'#title' => 'Redirect destination',
'#default_value' => $edit['destination'],
'#maxlength' => 250,
'#collapsible' => FALSE,
'#required' => TRUE,
'#description' => t('Specify a relative URL to redirect the user to, like `user/register`'),
);
return $form;
// validate the HTML form
case 'validate' :
$errors = array ();
foreach ($errors as $name => $message) {
form_set_error($name, $message);
}
return count($errors) == 0;
// process the HTML form to store configuration
case 'submit' :
$params = array (
'destination' => $edit['destination'],
);
return $params;
}
}
?>