11

We want to restrict our member signup page ( a contribution page ) to people who have registered to our Drupal site. Also, we'd want to have public contribution pages not associated with membership be accessible without login.

In Drupal, I could make the permissions for "CiviContribute: make online contributions" be not accessible for unauthenticated users, but then I wouldn't be able to have the public contribution pages accessible.

Is there such thing as a private contribution page? Or is there some other way of achieving our goal that I don't know about?

Thanks!

7

A short bit of custom code could take care of this (using the hook_civicrm_preProcess hook I think). It would need to check if the current page is your "sign-up" contribution page, and if it is, make sure that the user is currently logged in. If not, it would redirect to wherever you need.

Not positive this code is perfect, but it should get you pretty darn close...

function hook_civicrm_preProcess($formName, &$form) {

  $form_id = 7;   // set this to the specific form_id you wish to limit access to
  $redirect_path = 'home';  // set this to the url to redirect to if not logged in

  if ($formName == "CRM_Contribute_Form_Contribution_Main" && $form->_id == $form_id) {
    if (!user_is_logged_in()) {
      drupal_goto($redirect_path);
    }
  }

}
  • I think this is the most promising path, but I can't find any example code to work from. I've installed the civicrm development module and can see this helper info displayed on all contribution pages: hook_civicrm_preProcess called: formName is CRM_Contribute_Form_Contribution_Main. But I can see nothing distinct about my specific contribution page I want to make private other than the url which has the contribution id. If the hook just checks for the form name, I'm still in the same boat. All contribution pages are blocked. I need to be checking for an id to be distinct, right? – Peter_ Aug 13 '15 at 2:46
  • @Peter_, I have added a code snippet to my original response. – DaveD - BackOffice Thinking Aug 13 '15 at 21:46
  • Thanks much, I found this is code working, except that for reasons I don't understand, I'm limited to using the function name civicrm_developer_civicrm_preProcess. Then name hook_civicrm_preProcess won't work, or any others I try. I whittled down the civicrm developer module, that's where that particular function name comes from. – Peter_ Aug 14 '15 at 20:00
  • You need to create a new drupal module to contain the customization. then the routine name would drop in place of the "hook". It's actually quite easy but you should probably create a new question here for it. – DaveD - BackOffice Thinking Aug 14 '15 at 20:15
  • Ahh, I see. Function names must begin with the module file name. – Peter_ Aug 14 '15 at 20:42
6

I've got a custom extension that's designed to designate specific contribution pages as 'admin only', here: https://github.com/adixon/ca.civicrm.contributextra

The actual permissions to access 'admin only' contribution pages is just set to being logged in (I just wanted to hide them from anonymous access), so it'll do what you want. It'll also generate an admin link from contact summary pages' contribution tab to the designated admin-only contribution pages.

  • Thanks, I'm experimenting with your extension. I have one problem with it though. When I set a contribution page to admin-only, it's only viewable to drupal site admins. I'm not certain how to set it to authenticated users. Is there a config within civi or should I look at the code? I did modify the redirect to suit my needs. Thank you – Peter_ Oct 17 '15 at 0:23
  • 1
    You don't need to do anything other than mark it as admin-only - the current implementation only limits access to non-anonymous users, i.e. any authenticated user will have access to it. The relevant code is line 176, here: github.com/adixon/ca.civicrm.contributextra/blob/master/… – Alan Dixon Oct 19 '15 at 13:29
0

Please edit your question to expand on exactly why your goal is "to restrict our member signup page ... to people who have registered to our Drupal site"?

Is there something "extra special" about the people who have registered on your Drupal site such that they have to be pre-approved before they can register?

Is there any reason why people who haven't registered should not be able to view the membership page?

You may be able to accomplish what you need without resorting to code by making "Drupal account creation" compulsory on your signup page (done in "advanced settings" on the profile settings page) and requiring administrator approval for creating a Drupal user account.(Select "Visitors, but administrator approval is required" for Registration and cancellation on yoursite/admin/config/people/accounts.)

That way you could vet the "applicants" for membership before their Drupal account is created and refund the membership fees for those who are not acceptable for what ever reason.

  • HI JoAnne, to me it doesn't seem relevant to the question, which I thought was clear. But if it helps, let me give you some background, which I do not think belongs in the question itself. We are a maker space. We ask prospective members to come and meet us in person before we allow them to access the signup page. Since, crazy people and potentially dangerous tools don't go together so well. :-) To answer your question why shouldn't unauthenticated users be able to view the membership page, if they can view it, that means they can use it. – Peter_ Aug 12 '15 at 17:25
  • Sadly, making "Drupal Account creation" compulsory on the signup page doesn't accomplish the goal, because the anonymous user is already on the sign up page, the thing we don't want to have happen. – Peter_ Aug 13 '15 at 3:11
  • I realise that, which is why I asked for more information. I would argue that your ultimate goal is not "stop anonymous users from seeing our membership form" but rather "stop unsuitable people from having access to our maker space". You are new to this site, perhaps new to CiviCRM and were possibly seeking a non-code solution. A Drupal/Civicrm site is quite complex and there may have been ways to accomplish your ultimate goal that you had not thought of. Knowing what your ultimate goal was could have made a different approach, such as the one I outlined, a viable alternative. – JoAnne Aug 13 '15 at 8:41
-1

I might have misunderstood your question, but I think you are looking for something like the node access module, which it will allow you to restrict access to a page (ie membership page) based on user roles, ie authenticated users.

I'm not a Drupal user so please correct me if there are better solutions.

  • Civi pages aren't 'drupal nodes' so doubt it can be this simple, especially as civi throws ? in to paths which some drupal path based options don't appreciate' – petednz - fuzion Aug 12 '15 at 23:26
  • Drupal considers civicrm pages as non-node callbacks, so none of the node-specific permissions are applicable. Drupal gives primary permissions responsibility to the module that defines the callback (i.e. they are in the same table/code), and so the civicrm drupal module code already has allowed everyone to access any civicrm callback, and then has it's own permissions system (in the xml files). If you really wanted to use a custom Drupal module for this problem, you could use the menu hook and add a menu entry for the contribution pages and give it a custom permissions callback. – Alan Dixon Aug 31 '15 at 15:21

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.