Skip to Content Skip to Menu

🌟Discover the Joomla AI Plugin that wrote its own story! - CB Editor Assistant 1.1now for Joomla 3, 4 & 5!
✍️ 5-Day Free Trial, then 🎯 save up to 30% with our 🛍️ Intro Offer (First 50 users, ends Dec. 31)
🌲 Merry Christmas! Great savings on Professional and Developer Memberships! Get 25% off now with code XMAS-2024!

Can't get CB Code Field to work

  • mk3
  • mk3
  • OFFLINE
  • Posts: 137
  • Thanks: 2
  • Karma: -1
7 years 5 months ago - 7 years 5 months ago #295430 by mk3
Can't get CB Code Field to work was created by mk3
Hi there!

I have a cb_city field in user's profile. Sometimes users enter their city data as: "Moscow,Tula,Smolensk" (without spaces after brackets).
My goal is to put a little PHP code that will replace every "\S,\S" by a "\s,\s" (we talk about preg_replace function, to put spaces around commas in this sting). But it doesn't change anything.

So in this field inside "integration" tab under "CB Code Field" I enter the following code:
Code:
$string = '[value]'; $pattern = '/\S,\S/'; $replacement = ' , '; return preg_replace($pattern, $replacement, $string);

What's wrong here?
Last edit: 7 years 5 months ago by mk3.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48630
  • Thanks: 8307
  • Karma: 1446
7 years 5 months ago #295455 by krileon
Replied by krileon on topic Can't get CB Code Field to work
The parameters for a code field under the Integrations tab are for the Code Validation for custom PHP based field validation. Parameters for a code field are under the Parameters tab.


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 5 months ago #295470 by mk3
Replied by mk3 on topic Can't get CB Code Field to work
We are talking about a text field.
So you mean I have to do like on the screenshot? (joined to this message)
And is my code correct or do I need to change something?

Attachments:

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48630
  • Thanks: 8307
  • Karma: 1446
7 years 5 months ago #295498 by krileon
Replied by krileon on topic Can't get CB Code Field to work
That's not how CB Code Field works. You're trying to manipulate the value of a text field using CB Code Field and its Code Validation. It's just validation for validating the value of a field. You can not alter the field value from there. To execute and display code you need to use an actual Code field.


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