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) »
  • Support »
  • Using CiviCRM »
  • Using CiviMember (Moderator: Deepak Srivastava) »
  • Checking for current membership on contribution page
Pages: [1]

Author Topic: Checking for current membership on contribution page  (Read 1173 times)

jackrabbithanna

  • I post occasionally
  • **
  • Posts: 61
  • Karma: 3
  • Quick like bunny
    • http://www.skvare.com
  • CiviCRM version: 4.3.5
  • CMS version: Drupal 7.23
  • MySQL version: 5.1
  • PHP version: 5.3.3
Checking for current membership on contribution page
April 08, 2013, 03:37:38 pm
I have developed some code to prorate the fees and reset the end dates for a contribution page form.  I only want this to happen for new members.  Membership renewals should be full price.  I'm looking for a solution that will work even if the form is being used by a non-authenticated user(anonymous). 

Am I correct in assuming the form variable _currentMemberships is a good variable to check to see if the user currently entering data on the form is a member?

Secondly, I am also searching for a contact based on the first name, last name, and email address that is entered by the user through the form. Then I am determining whether their is a member record for that contact id....the problem is that it could be possible for that search  "civicrm_api('Contact','Get'" call to return multiple records.  So its not airtight. 

Is there a better way to determine whether the form was entered by a current member?

Code: [Select]
function mymodule_civicrm_validateForm( $formName, &$fields, &$files, &$form, &$errors ){
require_once 'api/api.php';

$contact = civicrm_api('Contact','Get',array('first_name' => $form->_elements[1]->_attributes['value'], 'last_name' => $form->_elements[3]->_attributes['value'], 'email_address' =>$form->_elements[14]->_attributes['value'], 'version' =>3));

$member=civicrm_api("Membership","get", array ('version' =>'3' , 'contact_id' => $contact['values'][1]['contact_id'] ));
if($formName == 'CRM_Contribute_Form_Contribution_Main' && $form->_values['title']=='Membership Signup' && $form->_id=='1' && !$form->_currentMemberships && !$member['count']){
//prorate the fee
}
}

Michael McAndrew

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1274
  • Karma: 55
    • Third Sector Design
  • CiviCRM version: various
  • CMS version: Nearly always Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Checking for current membership on contribution page
April 09, 2013, 02:00:24 am
Hey there,

I am pretty sure that there is some code in the online membership form that tries to establish whether the person filling in the form already has a membership, and if so, it adds it to that membership.  It might be worth having a look at that code and seeing if there is a function or so that  you can reuse.


Service providers: Grow your business, build your reputation and support CiviCRM. Become a partner today

routinet

  • I’m new here
  • *
  • Posts: 7
  • Karma: 0
  • CiviCRM version: Generally up-to-date
  • CMS version: Joomla
  • MySQL version: MySQL 5+
  • PHP version: PHP 5+
Re: Checking for current membership on contribution page
October 17, 2013, 01:15:21 pm
I know this is an old thread, but I ran into the same problem.  I posted my solution at http://forum.civicrm.org/index.php/topic,30332.0.html

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviMember (Moderator: Deepak Srivastava) »
  • Checking for current membership on contribution page

This forum was archived on 2017-11-26.