Posted by salientknight on April 21, 2011 at 4:45pm
I have custom PHP code that runs when a new user registers. I use the same code when a registered user fills out a form. The problem I am having is that for the user registration triggered event, I cannot seem to get values from any of the Tokens, $account or $user. The rest of the code works, but there are not values for those objects.
Is there a reason why this would work differently for User Registration?

Comments
More information:
This works great as a rule triggered by submitting a form:
[code]
$myFile = "my.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$phone=$data['components']['phone']['value'][0];
if($phone=="")$phone="000-000-0000";
$content ='uid='.$user->uid.'&firstName='.$data['components']['firstName']['value'][0].'&lastName='.$data['components']['lastName']['value'][0].'&org='.$data['components']['org']['value'][0].'&address1='.$data['components']['address1']['value'][0].'&city='.$data['components']['city']['value'][0].'&state='.$data['components']['state']['value'][0].'&zip='.$data['components']['zip']['value'][0].'&email='.$data['components']['email']['value'][0].'&phone='.$data['components']['phone']['value'][0].'&get='.$data['components']['get']['value'][0].PHP_EOL;
$stringData = $content;
fwrite($fh, $stringData);
fclose($fh);
[/code]
As a trigger cased by a user registration $account has 1 value, uid and none of the tokens work. I cannot seem to load the profile or get any value into my file but uid.
Please specify the event that
Please specify the event that triggers the code
Solved
I figured out the problem... its a caching issue.... the event is triggered by the user creating a new account... there is data in $account, but until the cache is cleared loading the profile does not return any data.
The question I'm working on now, is how to clear that cache so I can load the profile information.
Cache will not be a problem.
Cache will not be a problem. did you ever try to print $account in the action section and check what are the data available in the $account?
If you trigger the code using the event "User account has been created", the $account will populated with all the stuffs from the registration page.
Or else if you are sure, the problem is with cache, you can use clear_cache_all() to clear the entire cache, which will again be a performance issue
All I can get from the
All I can get from the $account variable is $account->uid. There is no way to print out the $account to the screen because the page changes... I've settled on just saving out the uid and handling the rest of the data collection with SQL/PHP