Closed (won't fix)
Project:
Webform
Version:
6.x-3.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
29 Mar 2009 at 10:56 UTC
Updated:
14 Jun 2010 at 21:41 UTC
Hi,
I have followed http://drupal.org/node/164526#comment-259353 and it works fine.
I then tried to add another conditional redirect which does not work properly. Following is the code I added. What happens is that I the inner condition always returns true and then goto alway happen - even is the node is owned by the user.
if (preg_match('/^node\/([0-9]+)\/submissions?/',$request)==1) // Works fine
{
if($node->uid != $user->uid) // Returns true always
{
drupal_goto('<front>');
}
}
Here is the code in its context (the function) -
function globalredirect_init() {
global $language;
global $user;
global $node;
/**
* We need to do a test to make sure we only clean up URL's for the main request. This stops modules such as
* the Ad Module which had its own script in its folder doing a bootstrap which invoked hook_init and caused some banners to get "cleaned up"
* See issues: http://drupal.org/node/205810 and http://drupal.org/node/278615
*/
if ($_SERVER['SCRIPT_NAME'] != $GLOBALS['base_path'] .'index.php') return FALSE;
/**
* If the site is in offline mode there is little point doing any of this as you might end up redirecting to a 503.
*/
if (variable_get('site_offline', 0) == 1) return FALSE;
/**
* Use of menu_get_item should be optional as it appears in some situations it causes WSOD's...
*/
$menu_check = variable_get('globalredirect_menu_check', GLOBALREDIRECT_FEATURE_DISABLED);
// Amir added - http://drupal.org/node/164526#comment-259353
// Get the request string (minus trailing slash e.g. node/123/)
$request = preg_replace('/\/$/', '', $_REQUEST['q']);
if (preg_match('/^node\/([0-9]+)$/',$request,$matches)==1 && $query_string == "")
{
$node = node_load($matches[1], NULL, TRUE);
if ($node->type == "webform")
{
drupal_goto('<front>');
// drupal_goto("/","",NULL,404);
}
}
// Amir added - In order to redirect from the pattern of /node/5/submissions AND /node/5/submission/43 (this is why the question mark in the end)
if (preg_match('/^node\/([0-9]+)\/submissions?/',$request)==1)
{
if($node->uid != $user->uid)
{
drupal_goto('<front>');
}
}
Any help will be really appreciated.
Thank!
Comments
Comment #1
amir simantov commentedAddition: I have found that the node is null in this context. So, how can I get it?
Comment #2
amir simantov commentedUpdate: Done it inside webform_submission_access which is in webform.module file.
Still, would like to know why $node was null...
Comment #3
nicholasthompsonI've no idea what you're trying to do - but it looks a little like you want it to redirect on submission... in which case why not use the redirect option within webforms?
Comment #4
amir simantov commented@#3
Thanks for your reply, but I want to do it type-wide and not for a specific webform item...
Comment #5
nicholasthompsonThis is a webform feature request - not a GlobalRedirect issue.
Looks like you want to setup a default Webform redirect...
Comment #6
quicksketchThis probably won't be added to Webform.
Comment #7
nicholasthompsonagreed - each node could just as easily be set to redirect on submit