Skip to Content Skip to Menu

Code Field - PHP code to display another field value for the same user

  • jcrimmel
  • jcrimmel
  • OFFLINE
  • Posts: 39
  • Thanks: 8
  • Karma: 1
1 year 11 months ago - 1 year 11 months ago #331282 by jcrimmel
Hello,

Looking for what is probably some pretty simple PHP help as I’m no expert at all.. FYI, I have CB Developer Package on J!4.2.3 and PHP 8.1.

Issue 1:
I have a Code Field that will be driven by PHP HTTPv2 code for an API call from another website. 

Code:
<?php $client = new http\Client; $request = new http\Client\Request; $request->setRequestUrl('https://HIDDENURL NAME.com/simple/price'); $request->setRequestMethod('GET'); $request->setQuery(new http\QueryString([   [b]  'ids' => 'Value of the user field ProjectName',[/b]     'vs_currencies' => 'usd' ])); $request->setHeaders([     'HIDDENINFO-Key' => 'HIDDENKEYINFO',     'HIDDENINFO-Host' => 'HIDDENINFO.com' ]); $client->enqueue($request)->send(); $response = $client->getResponse(); echo $response->getBody();

What I need to do is replace  'Value of the user field UserProjectName' with a field value found inside the user’s CB profile? I assume this should be pretty easy, but I am not great at writing PHP code.


Issue 2:
If given the option to use the PHP-based API call in the following formats, which is the better choice for the code field?
  • cURL
  • HTTPv1
  • HTTPv2
  • Unirest/Request 

Thanks so much
Last edit: 1 year 11 months ago by jcrimmel.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48419
  • Thanks: 8274
  • Karma: 1443
1 year 11 months ago #331291 by krileon
You can use substitutions within your code field. So for example if you have a field called cb_projectname then you can substitute it into your code with [cb_projectname]. Please keep in mind substitutions should always be treated as strings. So if you set them to a variable be sure they're surrounded by quotes. See the below tutorial for further substitution usage information.

www.joomlapolis.com/documentation/279-community-builder/tutorials/18353-using-substitutions-throughout-cb

If given the option to use the PHP-based API call in the following formats, which is the better choice for the code field?

Not sure what you're asking here. Use whatever request protocol you need.


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.
The following user(s) said Thank You: jcrimmel

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

  • jcrimmel
  • jcrimmel
  • OFFLINE
  • Posts: 39
  • Thanks: 8
  • Karma: 1
1 year 11 months ago #331306 by jcrimmel
Wow... that was much easier than I thought. Thank you!

I was able to get the correct test info to pull into each of the list rows through the API call. However, the formatting of the results needs to be cleaned up. I know that is a fix to do in the PHP code not a Community builder issue.... but if anyone would be willing to help me out with that, it would be greatly appreciated. I've been working with Joomla for 10 years and just started going deeper into CB in the last few weeks. While I can read and edit basic PHP, I have a difficult time writing it, so knowing where to start on formatting the results is puzzling me.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48419
  • Thanks: 8274
  • Karma: 1443
1 year 11 months ago #331309 by krileon
Formatting depends entirely on what format the response is. If it's JSON you can JSON decode it if not already decoded and process the JSON array or object as needed. Sorry, not much I can do for you in this regard as we don't provide custom coding assistance outside of our new Business Membership.


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.
The following user(s) said Thank You: jcrimmel

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

  • jcrimmel
  • jcrimmel
  • OFFLINE
  • Posts: 39
  • Thanks: 8
  • Karma: 1
1 year 11 months ago #331313 by jcrimmel
Thank you. So, I would be able to get assistance on this type of issue with the Business subscription?

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48419
  • Thanks: 8274
  • Karma: 1443
1 year 11 months ago #331318 by krileon
Yes.


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.

Moderators: beatnantkrileon
Powered by Kunena Forum