CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Hook for custom Redirect after processed Double Opt-In
Pages: [1]

Author Topic: Hook for custom Redirect after processed Double Opt-In  (Read 912 times)

pminf

  • I post occasionally
  • **
  • Posts: 56
  • Karma: 0
  • CiviCRM version: 4.3
  • CMS version: Drupal 7
  • MySQL version: 5.6
  • PHP version: 5.3
Hook for custom Redirect after processed Double Opt-In
July 10, 2013, 08:12:17 am
Hi,

I'm using profiles (html form snippet) on an external website (non-CiviCRM) to let users subscribe to newsletter groups. It fits our needs beside the fact, that the user ends up in CiviCRM, after he confirmed his newsletter subscription (double opt-in via e-mail). You can set a redirect-url, which is used after the form has been submitted. But there is no redirect-url setting for the final confirm process.

I guess I have to implement a redirect inside of a hook, but I'm not sure which one to use:

  • hook_civicrm_postProcess http://wiki.civicrm.org/confluence/display/CRMDOC43/hook_civicrm_postProcess
  • hook_civicrm_emailProcessor http://wiki.civicrm.org/confluence/display/CRMDOC43/hook_civicrm_emailProcessor
  • hook_civicrm_pageRun http://wiki.civicrm.org/confluence/display/CRMDOC43/hook_civicrm_pageRun

Which hook should be used here? Or is there another way to set a redirect-url for double opt-in confirmation?

Philipp

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: Hook for custom Redirect after processed Double Opt-In
July 24, 2013, 11:19:36 am
Not sure if you decided yet, but a couple quick thoughts:

 * Probably lean against hook_civicrm_emailProcessor unless one can show that the other hooks don't work.
 * When deciding which hook to use (and which arguments of the hook to use), it often helps to inspect the hooks a bit more visually. If you're running Drupal, see http://wiki.civicrm.org/confluence/display/CRMDOC43/Hook+Reference#HookReference-Inspectinghooks

pminf

  • I post occasionally
  • **
  • Posts: 56
  • Karma: 0
  • CiviCRM version: 4.3
  • CMS version: Drupal 7
  • MySQL version: 5.6
  • PHP version: 5.3
Re: Hook for custom Redirect after processed Double Opt-In
July 25, 2013, 12:07:49 am
Thank you for the instruction how to inspect hooks. I was always wondering, in which order civicrm hooks get called. Is there a kind of page hook live cycle?

To redirect users after an e-mail confirmation I'm now using an alterContent hook:

Code: [Select]
function mymodul_civicrm_alterContent(&$content, $context, $tplName, &$object){
if($object->getVar('_name') == 'CRM_Mailing_Page_Confirm'){
$cid = $_GET['cid'];
$sid = $_GET['sid'];
http_redirect('http://civicrm.external.com/thankyou.html', array('status' => 'added', 'cid' => $cid, 'sid' => $sid), false, HTTP_REDIRECT_PERM);
}
}

 I guess this hook is one of the last hooks to get called so no important functions will be missed.

Philipp
« Last Edit: July 25, 2013, 12:11:38 am by PhilippMikael »

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: Hook for custom Redirect after processed Double Opt-In
July 25, 2013, 10:09:24 am
Yes, alterContent is one of the last hooks. (Each CMS defines its own hooks that come later, but those obviously depend on the CMS.)

It would be interesting to have some documentation on the order of hook invocations. I'm not sure how that page would look (given that there are many hooks, and some of them are called at different times depending on the use-case).

The closest thing I can think of is a wiki page which discusses form-related hooks. However, that's a small portion/percentage of the hooks:

http://wiki.civicrm.org/confluence/display/CRMDOC43/QuickForm+Reference

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Hook for custom Redirect after processed Double Opt-In

This forum was archived on 2017-11-26.