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!

Display cb_phone field info in php with echo

  • mk3
  • mk3
  • OFFLINE
  • Posts: 137
  • Thanks: 2
  • Karma: -1
7 years 11 months ago #291573 by mk3
Hello.
I've didn't find information on the forum.
How can I do the same of
Code:
<?php $user = JFactory::getUser(); echo $user->phone; ?>
but for a CB field cb_phone ?

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48709
  • Thanks: 8319
  • Karma: 1447
7 years 11 months ago #291598 by krileon
Replied by krileon on topic Display cb_phone field info in php with echo
It's a CB field so you can't access it from Joomla user object as they don't join our database table. You need to use CB API for that. Specifically the getFields API or by accessing the CB user object directly. See the below on how to do this.

www.joomlapolis.com/documentation/279-community-builder/tutorials/18361-obtaining-field-values-through-getfields-api


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.

  • mk3
  • mk3
  • OFFLINE
  • Posts: 137
  • Thanks: 2
  • Karma: -1
7 years 11 months ago #291607 by mk3
I cannot paste code here...

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

  • mk3
  • mk3
  • OFFLINE
  • Posts: 137
  • Thanks: 2
  • Karma: -1
7 years 11 months ago - 7 years 11 months ago #291608 by mk3
When I write
Code:
<?php $cbUser =& CBuser::getInstance($user->id); if (!$cbUser) $cbUser =& CBuser::getInstance(null); $cb_phone = $cbUser->getField('cb_phone'); echo $cb_phone; ?>
inside VALUE
Code:
< inpu name="phone" maxlength="60" type="text" class="form" value="" / >
(the editor didn't let me paste "input" word inside code)
it breaks the full page output

But if I comment the php part, it works well.

Where is the problem?
Last edit: 7 years 11 months ago by mk3.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48709
  • Thanks: 8319
  • Karma: 1447
7 years 11 months ago - 7 years 11 months ago #291614 by krileon
Replied by krileon on topic Display cb_phone field info in php with echo
Wherever you're doing that likely doesn't have CB API loaded, which you can load using the below.

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

The getFields output also includes HTML. If you need raw database values use the below to build the CB user object and access it the same way you did using Joomlas.

www.joomlapolis.com/documentation/18359-establishing-a-cb-user-object


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.
Last edit: 7 years 11 months ago by krileon.

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

  • mk3
  • mk3
  • OFFLINE
  • Posts: 137
  • Thanks: 2
  • Karma: -1
7 years 11 months ago #291619 by mk3
Yeah, I thought about it. Thank's.
But it still didn't work.
I've posted this:
Code:
if ( ( ! file_exists( JPATH_SITE . '/libraries/CBLib/CBLib/Core/CBLib.php' ) ) || ( ! file_exists( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' ) ) ) { echo 'CB not installed'; return; } include_once( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' ); cbimport( 'cb.html' ); cbimport( 'language.front' );
and then this:
Code:
value="<?php //$cbUser =& CBuser::getInstance($user->id); if (!$cbUser) $cbUser =& CBuser::getInstance(null); echo $cbUser->getField('cb_phone'); ?>"

Then I simply user SQL to pull the phone number from users DB entry. This worked, but for future, I would like to understant why echo
Code:
$cbUser->getField('cb_phone');
is not working .

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

Moderators: beatnantkrileon
Powered by Kunena Forum