Skip to Content Skip to Menu

🕒 Save Time and Effort with CB Editor Assistant: Effortlessly create and refine content in Joomla 3, 4, & 5.
🎁 Limited Offer: Enjoy a 5-day FREE trial and save up to 30% afterward!

getting user id into a field

  • mjl1817
  • mjl1817
  • ONLINE
  • Posts: 45
  • Thanks: 7
  • Karma: 1
2 weeks 23 hours ago #339906 by mjl1817
getting user id into a field was created by mjl1817
I have tried additional ways of doing this but to no avail. this is part of a project to have all the css for all components used on the site merged into a single css passing the values via theme manager. I intend to use it to write about 10 universal themes. I am using gantry 5, joomla 5.2 and the most recent updates to community builder. I also have available to me joomla component builder which we tried first but it all began to become to combersum. can you tell me what I am doing wrong?   (YES I am being assisted by AI in this endevore)Issue: Unable to Retrieve User ID in Community Builder Custom Fields (Not a Valid Input Error)I am attempting to retrieve the user ID within a Community Builder (CB) custom field but keep receiving the error:
"Theme Selector: Not a valid input" or "Return value must be of type bool, null returned."What I've Tried:Below are the code attempts and configurations I've tried so far:Attempt 1: Fetching User ID with cbUser (Direct Method)
Code:
$user = cbUser::getMyInstance(); $userId = $user->id; return $userId;
Issue: "Not a valid input" – Potentially due to non-boolean return.Attempt 2: Using Fallback to Ensure Boolean Return
Code:
$user = cbUser::getMyInstance(); $userId = $user->id ?? 0; return ($userId > 0);
Issue: Same error message persists.Attempt 3: Using Joomla Core
Code:
JFactory
Instead of CBUser
Code:
$user = JFactory::getUser(); $userId = $user->id; return ($userId > 0);
Issue: Still receiving "Not a valid input."Attempt 4: Fetching CB User Parameter Directly
Code:
$user = cbUser::getMyInstance(); $userId = $user->getParam('id', 0); return ($userId > 0);
Issue: Still produces an error.Attempt 5: Using CB Query Field (SQL Attempt)
Code:
SELECT user_id FROM #__comprofiler WHERE user_id = '[user_id]' LIMIT 1;
Issue: Syntax error occurred with placeholder handling.Attempt 6: Returning User ID as a String
Code:
$user = cbUser::getMyInstance(); return (string) $user->id;
Issue: Same "Not a valid input."Attempt 7: Boolean Return with Conditional Check
Code:
$user = cbUser::getMyInstance(); $userId = $user->id; if (!empty($userId)) { return true; } return false;
Issue: Same error, still indicating CB expects a different handling.Attempt 8: Using CB Code Field for CSS Application
Code:
$user = cbUser::getMyInstance(); $theme = $user->getParam('cb_user_template_selector', ''); $doc = JFactory::getDocument(); $doc->addScriptDeclaration(" document.body.classList.add('" . htmlspecialchars($theme) . "'); "); return true;
Issue: Error continued.Attempt 9: Created a Separate Table for User ID and Theme
Code:
CREATE TABLE `taqlx_user_themes` ( `user_id` INT(11) NOT NULL, `theme` VARCHAR(100) NOT NULL, PRIMARY KEY (`user_id`), FOREIGN KEY (`user_id`) REFERENCES `taqlx_comprofiler` (`user_id`) ON DELETE CASCADE );
Issue: Error persisted when trying to fetch from this table as well.Attempt 10: Switched from CB Code Field to CB Text Field
  • Changed from CB Code Field to CB Text Field to avoid boolean errors.
  • Result: The field displayed but still returned
    Code:
    "Not a valid input"
    error when trying to fetch the value.
Database Check:
  • I confirmed the data in the database using the following SQL:
Code:
SELECT user_id, cb_user_template_selector FROM taqlx_comprofiler WHERE cb_user_template_selector IS NOT NULL;
  • The values are stored correctly in the table
    Code:
    taqlx_comprofiler
    .
Key Findings:
  • The error "Not a valid input" appears to be linked to how CB Code Fields expect a boolean return (
    Code:
    true
    or
    Code:
    false
    ).
  • Even when switching to CB Query Fields and Text Fields, the issue persisted.
  • The values are confirmed to be present in the database with correct formatting.
What I Need Help With:
  1. Does Community Builder restrict returning user data outside of its fields?
  2. How can I correctly retrieve the user ID in a CB Code Field?
  3. Is there a recommended way to use CB's internal methods or query handling to achieve this?
  4. Should I consider a plugin extension for this functionality?
Any guidance would be greatly appreciated! Thank you.

I wish I knew, Then we would both know.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48704
  • Thanks: 8319
  • Karma: 1447
2 weeks 22 hours ago #339911 by krileon
Replied by krileon on topic getting user id into a field

Does Community Builder restrict returning user data outside of its fields?

No.

How can I correctly retrieve the user ID in a CB Code Field?

Code fields directly give access to the user object via $user. This is noted in the codes parameter description. So to get the id you can simply use the following.
Code:
return $user->id;

Substitutions are also supported in code fields. So the below will also work.
Code:
return '[user_id]';

You getting "Not a valid input" tells me you aren't filling out the correct parameters. Code fields are configured under their Parameters tab. It sounds like you're configuring Integrations > CB Code Field, which is custom PHP based validation rules. Validation rules don't display code they simply validate the field based off your code.

Is there a recommended way to use CB's internal methods or query handling to achieve this?

For just displaying user id? No, using a Custom HTML field with [user_id] is the recommended way for displaying user id.

Should I consider a plugin extension for this functionality?

No, a plugin isn't required to display user id.


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 or Create an account to join the conversation.

  • mjl1817
  • mjl1817
  • ONLINE
  • Posts: 45
  • Thanks: 7
  • Karma: 1
2 weeks 22 hours ago #339913 by mjl1817
Replied by mjl1817 on topic getting user id into a field
that solved the problem. thank you..
 

I wish I knew, Then we would both know.
The following user(s) said Thank You: krileon

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum