Skip to Content Skip to Menu

🌟 CB Editor Assistant 1.0.0 is here! Discover our new AI Joomla Plugin that wrote its story! (and this banner!)
Start at just $12.50/month* or 💸 save 30% with our 🛍️ Black Friday Intro Offer for your subscription's lifetime
🎉 Black Friday sale is here! Great savings on professional and developer memberships! Get 25% off now with code BLACK-FRIDAY-2024!

How to set session cookie where value is base on CB field value?

  • MMDoege
  • MMDoege
  • OFFLINE
  • Posts: 98
  • Thanks: 3
  • Karma: 0
6 years 6 months ago #304321 by MMDoege
We need to set a cookie to save the current language_code used by CB user.
Because a user may change language setting before login we have put setting a cookie into auto action type code.

Triggers:
onAfterUserLoginSuccess

Code (PHP):
setcookie('cc_lang','[cb_language_code]'); (CB field result of [cb:config param="language_code"]) or

Code (JS inline):
// Set Expiry Date
var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
expires = "; expires=" + date.toUTCString();
// Set Cookie
document.cookie = 'cc_lang' + "=" + '[cb_language_code]' + expires + "; path=/";

Both auto actions trigger but do not set a cookie when one of both is unpublished.

We wonder if this generally is the correct way setting a cookie based on a CB field.
Do we have to put setting of cookie into the header section of the template?

Would be great to get a helping hand here.
Thanks.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48560
  • Thanks: 8292
  • Karma: 1445
6 years 6 months ago #304325 by krileon
Don't see why you'd need this. Use Joomlas built in multi-lingual functionality and you should have no issues transitioning to a logged in state. During registration they can also select their account language if you've the params field available. It is not necessary to create a custom language field or anything of the sort for this behavior; Joomla handles multi-lingual quite well.


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.

  • MMDoege
  • MMDoege
  • OFFLINE
  • Posts: 98
  • Thanks: 3
  • Karma: 0
6 years 6 months ago #304337 by MMDoege
Thank for replying.

We need this for a 3rd party Joomla chat, collaboration, and conferencing software app which is integrated with CB and operates very stable.
However they have their own language management for UI and transliteration services.
To get their UI in the language a user is working with in CB profile, language_code has to be set as a cookie to share this info.

Yes, this might be not an issue for CB and of course it is not an error generated.
Were just figuring out appropiate way to set cookie and where to place code required.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48560
  • Thanks: 8292
  • Karma: 1445
6 years 6 months ago #304341 by krileon
onAfterUserLoginSuccess trigger doesn't have any output so you can't use JS there. Just set the cookie with PHP and should work fine. See below for PHP cookie usage documentation.

php.net/manual/en/function.setcookie.php

That trigger should be fine though as it fires at the very end of the login process before login redirect. Just be user to set User to Self since that trigger doesn't have a 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.

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

Moderators: beatnantkrileon
Powered by Kunena Forum