Hi all,
I am trying to load a data from community builder's DB (_comprofiler)
I read the tutorial but i still could not understand how to go about it..
Basically, I want the username of a member to be loaded automatically into a text box in my Chronoform when a button on the profile is being clicked.
I did a search on the URL of the profile and found it to be like this:
"http://www.xxxxx.org/my-profile/userprofile/Tracy%20stevens"
as such, i can't really seem to understand how i can utilize this URL in Chronoform's DB record loader.
I did another search in comprofiler.html.php file and found the profile URL to be this(correct me if i am wrong):
"index.php?option=com_comprofiler&task=userProfile&user=' . $user->id . getCBprofileItemid( true ), false ) "
so in DB Record Loader, should the DB_field be: username ?
and the request param to be: user_id?
I'm not really good with php hence i would really appreciate if someone could provide some assistance.
Thank you!
I am trying to load a data from community builder's DB (_comprofiler)
I read the tutorial but i still could not understand how to go about it..
Basically, I want the username of a member to be loaded automatically into a text box in my Chronoform when a button on the profile is being clicked.
I did a search on the URL of the profile and found it to be like this:
"http://www.xxxxx.org/my-profile/userprofile/Tracy%20stevens"
as such, i can't really seem to understand how i can utilize this URL in Chronoform's DB record loader.
I did another search in comprofiler.html.php file and found the profile URL to be this(correct me if i am wrong):
"index.php?option=com_comprofiler&task=userProfile&user=' . $user->id . getCBprofileItemid( true ), false ) "
so in DB Record Loader, should the DB_field be: username ?
and the request param to be: user_id?
I'm not really good with php hence i would really appreciate if someone could provide some assistance.
Thank you!
Hello,
You will need a "custom code" action followed by a "db record loader".
In the custom code:
Then in the "db record loader", use the request param as "user_id", the db field is the field name which contains the user's id in the cb table!
Regards,
Max
You will need a "custom code" action followed by a "db record loader".
In the custom code:
<?php
$user = JFactory::getUser();
$form->data['user_id'] = $user['id'];
?>
Then in the "db record loader", use the request param as "user_id", the db field is the field name which contains the user's id in the cb table!
Regards,
Max
Thanks for the response!
I followed your instructions but i received a fatal error:
"Fatal error: Cannot use object of type JUser as array in xxxxxxx custom_code.php(19) : eval()'d code on line 3"
is there any way to solve the error?
I followed your instructions but i received a fatal error:
"Fatal error: Cannot use object of type JUser as array in xxxxxxx custom_code.php(19) : eval()'d code on line 3"
is there any way to solve the error?
Hi vsclassic,
Please try:
Bob
Please try:
<?php
$user =& JFactory::getUser();
$form->data['user_id'] = $user->id;
?>
Bob
Hi Bob,
Thanks for the speedy response!
It is working now!
However, i would like the text box in the form to display the username instead of the user_id. Would that be possible?
Thanks!
Thanks for the speedy response!
It is working now!
However, i would like the text box in the form to display the username instead of the user_id. Would that be possible?
Thanks!
Hi Bob,
I tried testing the code as a guest.
However, the form no longer displays the user_id of the profile.
I'm not sure whether the code only works for registered users, but i would require the code to work for guest. The main purpose of this code is to allow guest users to indicate their interest in the particular profile they just viewed on frontend by clicking a button on the profile.
Afterwhich, the code will capture the user_id of the profile that was viewed and automatically insert the user_id in the text box in chronoforms so that administrators will know the guest's indication of interest.
Hope you can help me on this. Thank you!
I tried testing the code as a guest.
However, the form no longer displays the user_id of the profile.
I'm not sure whether the code only works for registered users, but i would require the code to work for guest. The main purpose of this code is to allow guest users to indicate their interest in the particular profile they just viewed on frontend by clicking a button on the profile.
Afterwhich, the code will capture the user_id of the profile that was viewed and automatically insert the user_id in the text box in chronoforms so that administrators will know the guest's indication of interest.
Hope you can help me on this. Thank you!
Hi vsclassic,
Yes, that code will give you the user_id of the current user (which is 0 for a guest).
You'll need to find a way to access the User object for the user whose profile is clicked. There are two ways that I know of: you can use the user_id or the User Name. Assuming that Tracey Stevens is the name of that user and you can extract it somehow then code like this will give you the matching id:
Bob
Yes, that code will give you the user_id of the current user (which is 0 for a guest).
You'll need to find a way to access the User object for the user whose profile is clicked. There are two ways that I know of: you can use the user_id or the User Name. Assuming that Tracey Stevens is the name of that user and you can extract it somehow then code like this will give you the matching id:
<?php
$user = JFactory::getUser('user_name');
$form->data['user_id'] = $user->id;
?>
Bob
Hi Bob,
Thank you for the response.
I'm not sure whether i am right,(correct me if i am wrong) but wouldn't the code you provided me simply extracts the username of the current user which is "guest"?
or would it extract the username from the URL:
"http://www.xxxxx.org/my-profile/userprofile/Tracey%20stevens"
which will be "Tracey Stevens"?
Thank you!
Thank you for the response.
I'm not sure whether i am right,(correct me if i am wrong) but wouldn't the code you provided me simply extracts the username of the current user which is "guest"?
or would it extract the username from the URL:
"http://www.xxxxx.org/my-profile/userprofile/Tracey%20stevens"
which will be "Tracey Stevens"?
Thank you!
Hi vsclassic,
You're wrong. It will get the User ID of the user with the username 'user_name' - you need to replace that with a valid username for it to work though. Here's a better example
Bob
You're wrong. It will get the User ID of the user with the username 'user_name' - you need to replace that with a valid username for it to work though. Here's a better example
<?php
$user_name = 'Tracey Stevens';
$user =& JFactory::getUser($user_name );
$form->data['user_id'] = $user->id;
?>
Bob
This topic is locked and no more replies can be posted.