Where to add code on completion of registration?

17 years 8 months ago #17865 by michaelg
Hi,

I have two questions that I cannot seem to find an answer for by searching the forum...

Q1) Which file (and please specify filepath) contains the last bit of code to indicate successful registration?

The reason is, is I have some code (see below) which I want to add. The code will POST information from the registration to my newsletter software (12All). For it to work it needs to be added to the last step of the workflow of registration.

Q2) The code below was created for VirtueMart, its added when a purchase is made (if the buyer's chooses to subscribe, the code will subscribe the user). Since the data extract is specific to the VirtueMart database - I was wondering if someone could give me a few pointers on how to extract info from Community Builder to;

a) create a custom field to ask a question
b) field names for "name", "email", etc

Any help appreciated
Regards
Michael

p.s. the code below is inserted at the bottom of checkout.thankyou.php in VirtueMart.


[code:1]
//
// 12All data link code - START -
// The code will transfer the current sale to 12All list "BeA!ert"
//
// uncomment next line when testing
//echo 'Start of 12All code for BeA!ert'.'<br />';
// Locate the record in "_orders" table that matches the current value in $order_id and copy this record into $query_orderinfo
$query_orderinfo = "SELECT * FROM #__{vm}_orders WHERE order_id='$order_id'";
// Extract the user id from the record stored in $query_orderinfo and copy this into $query_userid
$db->query( $query_orderinfo );
$query_userid = $db->f( 'user_id' );
// uncomment next line when testing
//echo '$query_userid variable = '.$query_userid.'<br />';
// Locate the record in "_user_info" table that matches the current value in $query_userid and copy this into $query_userinfo
$query_userinfo = "SELECT * FROM #__{vm}_user_info WHERE user_id='$query_userid'";
// Extract the relevant info from the record stored in $query_userinfo and copy this into $form_data array
$db->query( $query_userinfo );
// Check if customer wants to subscribe to mailing list
$join_bealert = $db->f( 'extra_field_4' );
// uncomment next line when testing
//echo '$join_bealert variable = '.$join_bealert.'<br />';
if ($join_bealert == 'Y') {
//Subscribe customer to BeA!lert mailing list
// uncomment next line when testing
//echo 'Start of subscribe'.'<br />';
// transfer data from $query_userinfo to $form_data (and include extra 12All info)
// "left" fields = 12All field names, "right" fields = VirtueMart fields from "_vm_user_info" table.
$form_data = array(
'email' => $db->f( 'user_email' ),
'name' => $db->f( 'first_name' ),
'field[1]' => $db->f( 'extra_field_3' ), // Field: How did you hear about us ?
'p' => '7', // default setting obtained from checking 12All subscriber form
'nlbox[1]' => '6', // default setting obtained from checking 12All subscriber form
'funcml' => 'add', // value required to subscribe to 12All mailing list
);
// Set URL of mailing list manager software
$form_url = 'http://localhost/mailmgr/box.php';
// Convert $form_data into format suitable for POST sending
foreach ($form_data as $name => $value){
if (strlen($request_data) > 0)
$request_data .= '&';
$request_data .= $name.'='.urlencode($value);
}
// Build the POST request
$url = parse_url($form_url);
$request = "POST ".$url["path"]." HTTP/1.1\r\n"."Host: ".$url["host"]."\r\n"."Content-type: application/x-www-form-urlencoded\r\n"."Content-length: ".strlen($request_data)."\r\n\r\n".$request_data;
// Open the connection
$fp = fsockopen($url, 80, $err_num, $err_msg, 30);
if ($fp){
// Submit form
fputs($fp, $request);
// Get the response
while (!feof($fp))
$response .= fgets($fp, 1024);
fclose($fp);
// echo $response;
} else {
echo 'Could not connect to: '.htmlentities($url).'<br />';
echo 'Error #'.$err_num.': '.$err_msg;
exit;
}
} else {
// Do not subscribe
// uncomment next line when testing
//echo 'Start of do not subscribe'.'<br />';
}
// uncomment next line when testing
//echo 'End of 12All code for BeA!ert'.'<br />';
//
// 12All data link code - END -
//
[/code:1]

Please Log in to join the conversation.

17 years 8 months ago #17911 by michaelg
Hi,

I've done some digging and found that the end of this function located in comprofiler.class.php appears to suit my purpose of getting user info from a successful activation.

As you can see below I'm testing to see if I can extract the user's email address.

However, I'm not all yet 100% familar with Community Builder or Joomla that I can code without an example.

Could someone throw me a tidbit of code to;

a) identify the current user (the one that just got activated); and

b) how to retrieve their email address into a string; and

c) Also I created a custom field cb_joinbealertnewsletter to ask the user if they want to sign up to a newletter during registration, its two radio buttons (Yes/No). If someone could walk me through how to get this fields contents too, that would be great!

Regards
Michael

[code:1]
function activateUser(&$user, $mailToAdmins = true, $mailToUser = true) {
global $database, $ueConfig, $_PLUGINS;

$query = "UPDATE #__users"
. "\n SET block = 0, activation = ''"
. "\n WHERE id = '".$user->id."'"
// . "\n WHERE activation = '$activation'"
// . "\n AND block = 1"
;
$database->setQuery( $query );
if (!$database->query()) {
echo "SQL-unblock error: " . $database->stderr(true);
}
$cbNotification = new cbNotification();
if($mailToAdmins && $ueConfig==1) {
$cbNotification->sendToModerators(_UE_REG_ADMIN_SUB,$cbNotification->_replaceVariables(_UE_REG_ADMIN_MSG,$user));
}
$_PLUGINS->trigger( 'onUserActive', array($user,true));
if ($mailToUser) {
$cbNotification->sendFromSystem($user,getLangDefinition($ueConfig),getLangDefinition($ueConfig));
}

[/code:1]
$query_userid = "SELECT * FROM #__users WHERE id = '".$user->id."'";
$database->query( $query_userid );
$query_email = $database->setQuery( 'email' );
echo "users email address = ".$query_email."<br /><br />";
echo "this is the end of the activateuser function"."<br /><br />";
[code:1]
}
[/code:1]

Please Log in to join the conversation.

17 years 8 months ago #17915 by nant
I would download the API plugin documentation and study one or more of the core plugins.

You can do everything you want without hacking the code - just by writing a plugin. This way your solution will be able to survive future CB releases.

www.joomlapolis.com/component/option,com_docman/task,cat_view/gid,33/Itemid,36/

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.172 seconds

Facebook Twitter LinkedIn