Skip to Content Skip to Menu

Collecting value in CB action of CB fields

8 years 3 months ago #284600 by smalldragoon
Replied by smalldragoon on topic Collecting value in CB action of CB fields
HI
ok for debug :D, I found the standard CB action
What I need to do is to use curl to send an external API call and use CB extra fields as parameter
some sample code below, that is not working in the action now :


Code:
$url="https://xxx.fr" "&service_type=session-policy". "&policy=lioneloney". "&myemail=".$myemail; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); $application->enqueueMessage(JText::_($url), 'error'); // Set so curl_exec returns the result instead of outputting it. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Get the response and close the channel. $response = curl_exec($ch); //$application->enqueueMessage(JText::_($response), 'error'); curl_close($ch);

myemail should contain cbemail field value from logged user ( I need more parameters but if this one is working, easy to extend )

Thx !

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48541
  • Thanks: 8290
  • Karma: 1445
8 years 3 months ago #284619 by krileon
Replied by krileon on topic Collecting value in CB action of CB fields
You can use the Request action for that. It's an action specifically for sending HTTP calls and supports substitutions.


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.

8 years 3 months ago - 8 years 3 months ago #284701 by smalldragoon
Replied by smalldragoon on topic Collecting value in CB action of CB fields
Hi Krileon,

Could you please share or point to me( if I missed appropriate ) documentation :

- What are the different triggers available for each CB action available , this will avoids me to spend many time to figure out I have a chance to see something triggered. I guess it will be helpfull for everybody anyway.

- For the specific example of "onafteruser success" trigger, point to me on documentation for the user / automatic / Specific documentation. I still don't get the CB fields values ... if no documentation, provides me full and detailed explanation of ALL the steps I 'm supposed to implement ( or test ) and not only just the next step as I need to move forward by now.

- If I don't want to use CB HTTrequest, how can I get my curl ran and outputted properly ? can you please point me to documentation or potential restrictions
of CB action ( or this trigger ) for me to debug ?

- CB HTTPrequest : can I use the response and use it in a PHP code ., If yes, how ? Can you point me to documentation on CBaction "request" please ?
-> for now, I'm getting an error without using any parameter ( just URL defined ) :
Code:
Fatal error: Call to undefined function GuzzleHttp\choose_handler() in .......[..] /public_html/libraries/Prism/libs/GuzzleHttp/HandlerStack.php on line 40
CB autoaction is the freshest available ( in green in the plugin list )

- How CB action are launched on a page : If I have code ( PHP ) in a CB action , triggered by " on after login form", what triggers this action ? I assume this code should be run once only, when the login form is loaded. why do I have several time code executed ( linked to another post, I need to understand the behavior )

I choose to buy CB to make me win some time and I'm stuck for now with 1 answer per day. I can not spend hours doing troubleshooting or tests because I don't know what should be the right thing to define / configure because I'm missing documentation on normal behavior or way of use. I understand you can not answer straight forward but more frequent update are more than welcome !
Thx for your quick answer and support
Last edit: 8 years 3 months ago by smalldragoon.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48541
  • Thanks: 8290
  • Karma: 1445
8 years 3 months ago #284716 by krileon
Replied by krileon on topic Collecting value in CB action of CB fields

- What are the different triggers available for each CB action available , this will avoids me to spend many time to figure out I have a chance to see something triggered. I guess it will be helpfull for everybody anyway.

Click the trigger input. It's searchable and contains all the triggers available at this time. Any action can be ran on any trigger.

- For the specific example of "onafteruser success" trigger, point to me on documentation for the user / automatic / Specific documentation. I still don't get the CB fields values ... if no documentation, provides me full and detailed explanation of ALL the steps I 'm supposed to implement ( or test ) and not only just the next step as I need to move forward by now.

There is no documentation for triggers. There's only the below, which is out of date.

www.joomlapolis.com/documentation/279-community-builder/tutorials/18358-using-cb-triggers

To get field values in an action you just need to substitute them. See the below for substitution usage information. All actions are passed through substitutions.

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

- If I don't want to use CB HTTrequest, how can I get my curl ran and outputted properly ? can you please point me to documentation or potential restrictions
of CB action ( or this trigger ) for me to debug ?

You're not going to get any output on the trigger you're using. It has no output. So it can't possibly display anything. This is because just after onAfterUserLoginSuccess is a redirect.

- CB HTTPrequest : can I use the response and use it in a PHP code ., If yes, how ? Can you point me to documentation on CBaction "request" please ?

With a Request action, no. It just sends an HTTP request and that's all. For sending a custom cURL request and processing the results you need to write the code for that in a Code action with Method set to PHP. I can not help you with your custom code.

-> for now, I'm getting an error without using any parameter ( just URL defined ) :

What PHP version do you have?

- How CB action are launched on a page : If I have code ( PHP ) in a CB action , triggered by " on after login form", what triggers this action ? I assume this code should be run once only, when the login form is loaded. why do I have several time code executed ( linked to another post, I need to understand the behavior )

There can be more than 1 login forms displayed. If you've 2 modules or you're on the login page with a login module also displayed then that trigger fires once for each for 2 total. You can check if the session variable already exists. You could even do a simple static var cache like the below to stop double execute (I use these a lot).

Code:
static $LOADED = 0; if ( ! $LOADED++ ) { SINGLE_EXECUTE_CODE_HERE }

I choose to buy CB to make me win some time and I'm stuck for now with 1 answer per day. I can not spend hours doing troubleshooting or tests because I don't know what should be the right thing to define / configure because I'm missing documentation on normal behavior or way of use. I understand you can not answer straight forward but more frequent update are more than welcome !
Thx for your quick answer and support

You need a simple authentication plugin. It's like a custom 2-factor login with a session variable being the key. A Joomla authentication bot can accomplish this. You're also validating it after a user has successfully logged in instead of before using onBeforeLogin which can reject the login by setting a plugin error (see the below). No amount of documentation is going to help you with this as it's a very customized and specific implementation.

Code:
$_PLUGINS->_setErrorMSG( 'ERROR_MSG_HERE' ); $_PLUGINS->raiseError();


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: smalldragoon

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

8 years 3 months ago - 8 years 3 months ago #284751 by smalldragoon
Replied by smalldragoon on topic Collecting value in CB action of CB fields

krileon wrote:

- What are the different triggers available for each CB action available , this will avoids me to spend many time to figure out I have a chance to see something triggered. I guess it will be helpfull for everybody anyway.

Click the trigger input. It's searchable and contains all the triggers available at this time. Any action can be ran on any trigger.

Sorry, my bad english : what are the "configuration" of the existing triggers , ie : which ones generates output ( or not ), which ones has the user available ..etc... this is why I think it could be helpfull for everyone.

- For the specific example of "onafteruser success" trigger, point to me on documentation for the user / automatic / Specific documentation. I still don't get the CB fields values ... if no documentation, provides me full and detailed explanation of ALL the steps I 'm supposed to implement ( or test ) and not only just the next step as I need to move forward by now.

There is no documentation for triggers. There's only the below, which is out of date.

www.joomlapolis.com/documentation/279-community-builder/tutorials/18358-using-cb-triggers

To get field values in an action you just need to substitute them. See the below for substitution usage information. All actions are passed through substitutions.

I'm in a code Action
Trigger is ""on afteruser login success"
in general Tab , user option is set to "User" , ( changer from default "automatic")
based on one of the tutorial, I have implemented the following code :


Code:
// Get a handle to the Joomla application object for debug $application = JFactory::getApplication(); /// Global $_CB_framework; // $cbUser =& CBuser::getInstance( (int) $_CB_framework->myId() ); if ( ! $cbUser ) { $cbUser =& CBuser::getInstance( null ); } // different attemps to grab username $user =& $cbUser->getUserData(); $myusername = $cbUser->getField( 'username' ); $usernameADV = $cbUser->getField( 'username', 'no value retrieved ', 'txt', 'none', 'list' ); ////////////////////////////////////////////// $application->enqueueMessage(JText::_('usernameADV :' . $usernameADV .'####'), 'error'); $application->enqueueMessage(JText::_('myusername : ' . $myusername .'####' ), 'error'); $application->enqueueMessage(JText::_('myusername : ' . $user->Username.'####' ), 'error'); //////******** DEBUG *******************//// //Retrieve joomla standard field to validate we are connected properly $stduser=JFactory::getUser()->get('username'); ///*************************/// $application->enqueueMessage(JText::_('stduser: ' . $stduser), 'error');



Tutorial or other methods found in forum are not working to display CB value ( while I double chcked that user is properly logged in )
Anything I'm missing ?



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

- If I don't want to use CB HTTrequest, how can I get my curl ran and outputted properly ? can you please point me to documentation or potential restrictions
of CB action ( or this trigger ) for me to debug ?

You're not going to get any output on the trigger you're using. It has no output. So it can't possibly display anything. This is because just after onAfterUserLoginSuccess is a redirect.
OK

- CB HTTPrequest : can I use the response and use it in a PHP code ., If yes, how ? Can you point me to documentation on CBaction "request" please ?

With a Request action, no. It just sends an HTTP request and that's all. For sending a custom cURL request and processing the results you need to write the code for that in a Code action with Method set to PHP. I can not help you with your custom code.

I'm in a code Action ( PHP )
Trigger is ""on afteruser login success"
code is basic :

Code:
$url="https://www.mysite.com/query?toto=34554RF". "&sessid=".$MyREFSessionID; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); $application->enqueueMessage(JText::_($url), 'message'); // Set so curl_exec returns the result instead of outputting it. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Get the response and close the channel. $response = curl_exec($ch); //$application->enqueueMessage(JText::_($response), 'error'); curl_close($ch); //echo $response; $pieces = explode("&", $response); [ ...etc ]
Curl is not executed while some other action before in the PHP are. any restrictions ?

-> for now, I'm getting an error without using any parameter ( just URL defined ) :

What PHP version do you have?
I tried 5.5, 5.6 and just switched to 7.0. any min requirement ?

- How CB action are launched on a page : If I have code ( PHP ) in a CB action , triggered by " on after login form", what triggers this action ? I assume this code should be run once only, when the login form is loaded. why do I have several time code executed ( linked to another post, I need to understand the behavior )

There can be more than 1 login forms displayed. If you've 2 modules or you're on the login page with a login module also displayed then that trigger fires once for each for 2 total. You can check if the session variable already exists. You could even do a simple static var cache like the below to stop double execute (I use these a lot).

Code:
static $LOADED = 0; if ( ! $LOADED++ ) { SINGLE_EXECUTE_CODE_HERE }

I tried equivalent ... it's a joomla issue, not CB . I will do anther way then ...

I choose to buy CB to make me win some time and I'm stuck for now with 1 answer per day. I can not spend hours doing troubleshooting or tests because I don't know what should be the right thing to define / configure because I'm missing documentation on normal behavior or way of use. I understand you can not answer straight forward but more frequent update are more than welcome !
Thx for your quick answer and support

You need a simple authentication plugin. It's like a custom 2-factor login with a session variable being the key. A Joomla authentication bot can accomplish this. You're also validating it after a user has successfully logged in instead of before using onBeforeLogin which can reject the login by setting a plugin error (see the below). No amount of documentation is going to help you with this as it's a very customized and specific implementation.

Code:
$_PLUGINS->_setErrorMSG( 'ERROR_MSG_HERE' ); $_PLUGINS->raiseError();

Last edit: 8 years 3 months ago by smalldragoon.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48541
  • Thanks: 8290
  • Karma: 1445
8 years 3 months ago #284759 by krileon
Replied by krileon on topic Collecting value in CB action of CB fields

Sorry, my bad english : what are the "configuration" of the existing triggers , ie : which ones generates output ( or not ), which ones has the user available ..etc... this is why I think it could be helpfull for everyone.

Ones with output almost always are obvious in that sense. For example they often contain "Display", "Form", etc.. Some of the older CB triggers are less obvious though, but from here on triggers should be more clear as to what they do and where. If you're unsure if a trigger has output or not you can simply ask and we'll be happy to help or you can dig into the code and find where it's being executed. I understand such documentation would be helpful, but we're a team of 3 with 2 full time. I don't have the time to maintain such documentation. So my time is spent on support and development. One would need to be sacrificed for documentation (that or my entire personal life).

Tutorial or other methods found in forum are not working to display CB value ( while I double chcked that user is properly logged in )
Anything I'm missing ?

Your enqueueMessage usages should output following the redirect. That's standard Joomla behavior unless your action didn't execute, Joomla cleared the queue, or your template doesn't output message queue. You do not need to build a user object for user data in an action. Just substitute it in. For example [username]. Treat all substitutions, at the very least, as string values. So if you need to assign it to a variable surround it with quotes.

Curl is not executed while some other action before in the PHP are. any restrictions ?

The action is likely executing, but your code maybe erroring (e.g. you've using $application without declaring it then calling a function on it). I can not help you debug your custom code. You can also put your custom code in a PHP file and just do an include in the code action as well if you want a PHP file for it, but you'll lose support for substitutions in your code doing this. If the action isn't executing it's probably failing at the conditions if configured. If an action executed before it does a redirect of any kind then your action also will never execute. The order of your actions on the same trigger is important in that regard.

I tried 5.5, 5.6 and just switched to 7.0. any min requirement ?

Our current version of Guzzle isn't PHP7 compatible. It has known PHP7 bugs that we can't address yet until CB 2.1 where we'll have to move our minimum PHP requirement to 5.4 to update Guzzle. I recommend PHP 5.6.


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