Redirect after imported and invitations sent...

benone - October 24, 2009 - 21:41
Project:Drupal Contact List Importer
Version:6.x-2.x-dev
Component:Miscellaneous
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed
Description

I'd like to have dcl_importer_invite as one of steps after creating account.
So I'd like to set a path where the user would go after submit Send Invite Request button.
Now it's just staying on the same page...
Where in the code I can change / add it ?

#1

hadsie - October 25, 2009 - 03:33

Easiest way to do it is to override hook_import_action() and return the URL on the submit operation.

something like:

function mymodule_import_action($op, $a2, $a3 = NULL) {
  if ($op == 'submit') {
    return $redir_url;
  }
}

Where $redir_url is the url you want to redirect to. I haven't tested that but hopefully it works. :)

#2

benone - October 25, 2009 - 06:16

Hey, thank you.
Can I ask for example ?
I understand it should be placed in template.php ?
Please, provide an example if you can..

#3

benone - October 25, 2009 - 06:36

I would like to paste this line:

$form_state['redirect'] = 'some/other/path';

..somewhere into the module.. but where ? :)

#4

hadsie - October 25, 2009 - 12:35

yeah, the hook i suggested allows you to do just that. that way you don't need to ever modify the module code which would break your upgrade path.

You need to create your own module if you haven't already. And then you can just add the code snippet above into your .module file and change the "mymodule" part of the function definition to the actual name of your module.

#5

benone - October 25, 2009 - 12:38

Thanks hadsie !
And it will know that it's the form from dcl_importer ?
Where is the info about dcl_importer module in that code snippet ?

Many thanks again.

#6

hadsie - October 25, 2009 - 12:43

ahh yeah, it doesn't need any additional information. the dcl_importer module declares a hook call hook_import_action(), when you create the function called mymodule_import_action() drupal will find the hook and evaluate it when it's suppose to. The key is really in the name of the function.

#7

benone - October 25, 2009 - 12:46

I am doing it right now.
The last question: where shuold I put a path to go after submit ?
return $redir_url; change to return 'user/%uid/edit'; ?

#8

hadsie - October 25, 2009 - 12:53

exactly. obviously %uid would need a valid uid though.

#9

benone - October 25, 2009 - 12:57

function abc_import_action($op, $a2, $a3 = NULL) {
global $user;
$redir_url = 'user/'.$user->uid.'/edit/profile';
  if ($op == 'submit') {
    return $redir_url;
  }
}

Works perfect like that ! :)
Many thanks.

#10

hadsie - October 25, 2009 - 13:00
Status:active» fixed

awesome! :)

#11

benone - October 25, 2009 - 13:17
Status:fixed» active

Ok, I don't expect the answer for this question , coz I already had my last ... :)
If you are still there ...

How to add the link "Skip this step" next to the 'Get My Contacts' button ?
Can I do it also not hacking the module ?

#12

hadsie - October 25, 2009 - 13:22

The easiest way would probably be to use hook_form_alter in your module and add the link to the form... http://api.drupal.org/api/function/hook_form_alter/6

#13

benone - October 25, 2009 - 13:31

I don't understant those alters. Have no idea how it works.... I know it's probably easy but I always hack the modules, coz don't know how is possible to put something to the module ant in the same time not putting it... :) arggghh

I did like that in openinviter_engine.module file:

After:

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Get My Contacts'),
  );

I put:

  global $user;
  $redir_url = 'user/'.$user->uid.'/edit/profile';
  $form['cancel'] = array(
'#type' => 'markup',
'#value' => l(t('Skip this step'), $redir_url),
  );

And it's working :)

Would you show me the same using this hook_form_alter ?

#14

benone - October 25, 2009 - 14:05

Ok, I learned it. Now understand.

function abc_form_alter(&$form, $form_state, $form_id) {

  if ($form_id == 'dcl_importer_form') {

  global $user;
  $redir_url = 'user/'.$user->uid.'/edit/profile';
  $form['cancel'] = array(
'#type' => 'markup',
'#value' => l(t('Skip this step'), $redir_url),
  );

  }
}

Thanks for your hints !
:)

#15

hadsie - October 28, 2009 - 02:12
Status:active» fixed

awesome! :)

#16

System Message - November 11, 2009 - 02:20
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.