Skip to Content Skip to Menu

[SOLVED] check to see if field has data (for Advanced Module Manager)

  • cpaschen
  • cpaschen
  • OFFLINE
  • Posts: 328
  • Thanks: 42
  • Karma: 9
7 years 4 months ago - 7 years 4 months ago #294645 by cpaschen
I've trying to use the PHP option of the Regular Labs Advanced Module Manager to control when a specific module displays.
I basically just need to run some php code and return true if a field has had some data entered.
The field being checked is a Query Drop Down (Single Select) type.

I've reviewed the documentation here:
www.joomlapolis.com/documentation/279-community-builder/tutorials/18361-obtaining-field-values-through-getfields-api
and here:
www.joomlapolis.com/documentation/18359-establishing-a-cb-user-object

And I'm still not able to just come up with the proper syntax to test in a php IF to see if cb_myfield is empty (i.e. doesn't have anything selected yet).

Can you tell me the proper way to get the values (i.e. getMyUserDataInstance or getMyInstance) and then what syntax to actually get the contents of that field?
Last edit: 7 years 4 months ago by krileon. Reason: Added [SOLVED] tag to subject

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48438
  • Thanks: 8275
  • Karma: 1443
7 years 4 months ago #294660 by krileon
You don't need getFields API. You just need the CB user object so you can test against its raw stored values. None of this will work if CB API isn't loaded on the page you're trying to execute it on though. See the below regarding using a CB user object.

www.joomlapolis.com/documentation/279-community-builder/tutorials/18359-establishing-a-cb-user-object

Example as follows to get a fields raw value.

Code:
$user = CBuser::getUserDataInstance( USER_ID_HERE ); $fieldValue = $user->get( 'FILED_NAME_HERE' );

See the below on how to load CB API externally.

www.joomlapolis.com/documentation/279-community-builder/tutorials/18357-including-cb-api-for-usage-outside-of-cb


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.

  • cpaschen
  • cpaschen
  • OFFLINE
  • Posts: 328
  • Thanks: 42
  • Karma: 9
7 years 4 months ago #294689 by cpaschen
Thanks! Got it working.

For those reading this later and want to use Advanced Module Manager and restrict the display of a module based on a CB field here what you put in the Custom PHP area of the Assignments tab:
Code:
$user = CBuser::getMyUserDataInstance(); $fieldValue = $user->get( 'FILED_NAME_HERE' ); return ($fieldValue == 0);

You can modify the 'return' test. In this example, it just tests for any entry with a value of 0. You could change that to whatever test you want that returns TRUE to display the module, FALSE to hide the module.
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