We've a page (in Drupal) outside of CiviCRM for "editors" (mean, users with restricted permissions) to perform some civicrm tasks.

From this page civicrm forms is being opened in modal frame via .crm-popup class added to form open links. There are also hooks being used (_pre and _postProcess) for these forms.

Drupal page should be refreshed after form submit (in order to show editors their edits); but each form submit summons a js status message CRM_Core_Session::setStatus(ts('Your information has been saved.'), ts('Thank you.'), 'success'); from civicrm\CRM\Profile\Form\Edit.php.

And we're lost in how (mean, where would be a right place) to add something like location.reload which, ideally, should be fired right after status message close. Or, may be, it should be added at hook_postProcess level via "header(refresh)" (we've made some attempts doing this and failed though)?

Any clue form true js / jquery experts, please!

  • yurg - can you share more about how you approached getting a modal popup of civi function for a drupal user. my goal is to provide a drupal user who has no access to CiviCRM to create a new CiviCRM Group. Sounds like you are doing something along those lines.
    – petednz - fuzion
    Commented Jul 1, 2016 at 0:47
  • petednz: I've learned user has to have an access to some civicrm parts (in your case it'd be "CiviCRM: edit groups" and may be "Access Civicrm"). In order to prevent users from accidental access to /civicrm/ path, I use drupal_goto() (not smart, but works). As for modals: there are basically two options: #1. add "crm-popup" class: l(t('Add group'), 'civicrm/group/add', array('attributes' => array('class' => 'crm-popup'), 'query' => array('cid' => $contact['cid'], 'reset' => 1)); or #2. catch link in JS file: $('#MyLinkID').on('click', CRM.popup); #2 allows further Civi JS API usage.
    – yurg
    Commented Jul 1, 2016 at 9:11
  • Thank you yurg. I don't have a problem with the users having drupal permission for 'edit groups' etc. This is more to keep their life easy than to lock them out of civi entirely. So either of your solutions (just) require a custom module? Did you ever consider piggy-backing on something like drupal.org/project/modal_forms
    – petednz - fuzion
    Commented Jul 1, 2016 at 19:24
  • civicrm has it's own modal forms tool (presumable based on jQueryUI), so there is no need to add smth. on top of it; there is no need of an extra module either if only thing you need is a form opened in a modal frame. In this case you can print simple HTML link (in case you don't want to utilize drupal l() function I mentioned in a prev.comment). It can be as simple as: **< a class=crm-popup href=civicrm/group/add?reset=1 > Create a New Group < / a > **
    – yurg
    Commented Jul 1, 2016 at 21:40
  • really appreciate your trying to help me on this. and glad to hear this could be simple. so presumably once i figure what i need to put in the theme for that class to function then the link as you gave me (cleaned up to <a class="crm-popup" href="/civicrm/group/add?reset=1"> Create a New Group </a>) may be enough. but i haven't followed what I would need to add to the theme. sorry.
    – petednz - fuzion
    Commented Jul 1, 2016 at 23:38

2 Answers 2


If you want the entire page to refresh during a popup form submission, then essentially you want to disable the ajax submit. You can do so in your _pre hook by writing:

  • It works, thanks! But what if I a) want to refresh only part of the page b) this page is outside of civicrm/ path c) would be nice to call fancy crm.status message after page/part of the page refresh?
    – yurg
    Commented Mar 4, 2016 at 21:54
  • Using ajax to refresh part of the page in Drupal really has nothing to do with CiviCRM - you'll need to consult Drupal docs for that. If you get that working, calling CRM.status would be the easy part.
    – Coleman
    Commented Mar 5, 2016 at 2:18
  • You're right, main question here is not in how to update a page in Drupal, but rather in how to update page in Drupal after Civicrm form submit (where Civicrm form has been called in modal frame from Drupal page using .crm-popup link class). Parts of a puzzle, which I'm not able to put together yet.
    – yurg
    Commented Mar 6, 2016 at 22:17
  • You want to listen for the "crmPopupFormSuccess" event. See wiki.civicrm.org/confluence/display/CRMDOC/Ajax+Pages+and+Forms
    – Coleman
    Commented Mar 7, 2016 at 1:43
  • How do you do it?!! Have read this page a million times, was blind until you cast your spells upon me, so now I can see!!!
    – yurg
    Commented Mar 7, 2016 at 16:32

Here is a code for copy&paste, in case anyone wants it:

    .on('click', 'a.LINK_CLASS_or_ID', CRM.popup)
        .on('crmPopupFormSuccess', 'a.LINK_CLASS_or_ID', function() {     
 // Die, default CRM.alert!! I was looking how to kill you for weeks
        CRM.alert= function() {}; 
// Attaching civicrm magic to any page element              
  // Here we go
  // Let us tell users what we are doing  
       CRM.status('Success! Refreshing a corresponded piece of content', 'Success', 'success' ); 
  • Instead of calling crmSnippet('refresh') directly, take a look at the CRM.refreshParent helper function - it will do it for you without you needing to know the exact element of the ajax container.
    – Coleman
    Commented Mar 7, 2016 at 19:21
  • You might won't believe, have tried to make use of CRM.refreshParent almost the whole day, but all I've got is ' Cannot read property 'stopPropagation' of undefined'. Basically, I'd like to reload a DataTable - powered table, not the whole page, but this gets even more complicated, so only thing which more or less works is make whole page refresh, unfortunately.
    – yurg
    Commented Mar 7, 2016 at 20:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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