4

I'm writing an extension implementing hook_civicrm_post to move contributions from individual to household if the individual is part of a household. However, I'd like the form to either redirect to the HOUSEHOLD summary or to display something about the household in the Successfully saved status message popup so the user doesn't think the contribution entry failed.

Any ideas how I can do either of those things from the extension?

3

You can redirect using the

CRM_Utils_System::redirect($urlyouwant)

and use

CRM_Utils_System::url

to build the url itself.

you can as well display pop up messages using CRM.alert() or CRM.status()

That page describes the options or how to call them from php too: http://wiki.civicrm.org/confluence/display/CRMDOC/Notifications+and+Confirmations

3

Xavier's answer is generally right but because you are in the context of a form I advise don't use the function CRM_Utils_System::redirect because that is a rather blunt instrument, and breaks pop-ups and other ajax-based forms (which don't follow the normal round-trip webpage lifecycle). Instead from your hook you can call CRM_Core_Session::singleton()->pushUserContext($urlYouWant); and the form controller will take care of doing the actual redirect or other appropriate action.

So from your hook you'd do:

$url = CRM_Utils_System::url('civicrm/my/path', 'argumet=1');
CRM_Core_Session::singleton()->pushUserContext($url);
CRM_Core_Session::setStatus(ts('Your foo has been barred'), ts('Saved'), 'success');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.