×

Error

Please login first

[SOLVED] Setting User Profile Values from AutoAction

10 years 1 month ago - 10 years 1 month ago #243766 by rmwalker
User: Automatic
Trigger: onAfterUserApproval
Type: Code
Method: PHP (eval)

I've reviewed some of the articles in the forum. If I want to update user profile values with PHP code in my AutoAction, Would I just need to add code similar to the following? Not sure about the syntax:
$cbUser =& CBuser::getInstance( $user->id );
$cbUser->set( 'cb_jbid', $My_Value );
$cbUser->set( 'cb_jbactive', 'Yes' );
$cbUser->store();

Please Log in to join the conversation.

10 years 1 month ago #243796 by krileon
Replied by krileon on topic Setting User Profile Values from AutoAction
That gives the cbUser class. You'll need the user object class it self. Please see the below.

$user = CBuser::getUserDataInstance( '[user_id]' );
$user->set( 'cb_jbid', $My_Value );
$user->set( 'cb_jbactive', 'Yes' );
$user->store();

If cb_jbactive is a checkbox field be sure you use values 1 (Yes) and 0 (No).


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

10 years 1 month ago #243797 by rmwalker
Replied by rmwalker on topic Setting User Profile Values from AutoAction
In this case "cb_jbactive" is a text field with 3 possible values (Yes, No, Lifetime). Does that change the syntax?

Please Log in to join the conversation.

10 years 1 month ago - 10 years 1 month ago #243799 by rmwalker
Replied by rmwalker on topic Setting User Profile Values from AutoAction
The "Trigger" I'm using is "onAfterUserRegistrationMailsSent". So then to apply a "CBuser::getInstance" statement to my AutoAction code-block, I could insert these 4 lines at the bottom of my code to write-back to the registered user record. Do I need to do a store() after each set statement? I've inserted some newlines in the VtInsert statement just for readability.
include 'butler/include/Butler.php';

$userpass = Vt_Rand_Str(10);
$JBuser_Id = VtInsert(	$newuser = '[username]', 
			$newpass = $userpass, 
			$newemail = '[email]', 
			$newfirstname = '[firstname]', 
			$newlastname = '[lastname]', 
			$newaddress = '[cb_address]', 
			$newcity = '[cb_city]', 
			$newstate = '[cb_state]', 
			$newcountry = '[cb_country]', 
			$newzip = '[cb_zipcode]', 
			$newphone = '[cb_phonenumber]', 
			$newmobile = '[cb_phonenumber]'
			);

$cbUser = CBuser::getUserDataInstance( '[user_id]' );
$cbUser->set( 'cb_jbid', $JBuser_Id );
$cbUser->set( 'cb_jbactive', 'Yes' );
$cbUser->store();

Please Log in to join the conversation.

10 years 1 month ago #243800 by rmwalker
Replied by rmwalker on topic Setting User Profile Values from AutoAction
Worked perfectly -- mark this one solved!

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.188 seconds

Facebook Twitter LinkedIn