doesnt work with advanced profile kit
thet0olman - April 4, 2009 - 17:35
| Project: | User Referral |
| Version: | 5.x-1.x-dev |
| Component: | User interface |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
Im using the advanced profile kit and I cant seem to find the referral link anywhere.
Also I would much rather have the new person signing up to put in the email address or user name of the referrer in a field on the sign up page.
this thread
seems to talk about that and I merged the code into the end of the refferers module but it didnt seem to do anything.
Any ideas? Thanks in advance

#1
ok i managed to get the referrers feild to work on the new user registration form but it give the points to the person signing up instead of the person who referred them. I played around with the code and could acheive any results.
/**
* Implement hook_form_alter
*
**/
function referral_form_alter($form_id, &$form) {
switch ($form_id) {
case 'user_register':
$form['referral'] = array(
'#type' => 'textfield',
'#title' => t('Referral'),
//'#default_value' => $node->body,
'#description' => t('If you were referred to our site by an existing member, you may enter either
their username on this site or the email address which they have on file with us.'),
'#required' => false);
break;
}
}
/**
* Implementation of hook_user
*/
function referral_user_reg($op, &$edit, &$account, $category = NULL) {
switch ($op) {
case 'validate':
global $form_values;
if (isset($form_values['referral'])) {
// did they enter an email address or username?
if (valid_email_address($form_values['referral'])) $check = array('mail'=>$form_values['referral']);
else $check = array('name'=>$form_values['referral']);
// and is it in the db
if (!user_load($check)) form_set_error('referral',"the email address or username that you have entered does not belong to a member of
our site");
}
break;
case 'insert':
global $form_values;
// need to do same checks now as we did to validate - except that we will know the member is valid
if (isset($form_values['referral'])) {
// did they enter an email address or username?
if (valid_email_address($form_values['referral'])) $check = array('mail'=>$form_values['referral']);
else $check = array('name'=>$form_values['referral']);
// and is it in the db
$member = user_load($check);
create_referral($member->uid, $account->uid); // insert the referral into referals table
}
break;
}
}
// insert a new entry in referrals table if someone enters a referrer when they register
// - $old_member is uid of referring member (existing member)
// - $new_member is uid of regsitering member
function create_referral ($old_member, $new_member) {
// create an entry in the referral table
$ts = time();
$host = $_SERVER['REMOTE_ADDR']; // doesn't really mean anything
db_query("insert into referral (uid, referral_uid, created, flag, host, http_referer)
values ($new_member, $old_member, $ts, 0, '$host', '')");
//plus lets add the points for being referred
if (module_exists('userpoints')) {
$points = variable_get(REFERRAL_USERPOINTS, 1);
userpoints_userpointsapi('points', $points, $old_member, 'Referral');
}
}