Can't get CB Code Field to work

6 years 8 months ago - 6 years 8 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:
$string = '[value]';
$pattern = '/\S,\S/';
$replacement = ' , ';
return preg_replace($pattern, $replacement, $string);

What's wrong here?

Please Log in to join the conversation.

6 years 8 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 to join the conversation.

6 years 8 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 to join the conversation.

6 years 8 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 to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.197 seconds

Facebook Twitter LinkedIn