164 Posts
redback
10 years ago
15
Topic

Hello Sebloders,

need help by the following problem:

  • Fieldtype: Checkbox
  • Saving values in talbe: option1,option2,option3
  • Value seperator: "," without space

My wish:

Getting the option output like this: "option1, option2, option3" (Space after "," although its saved without).

Approach: Fix it over the typo plugin, but how?

Thanks for your help. Best Chris

Get a VIP membership
4229 Posts
Kadministrator
10 years ago
1
Level 1

Hi,

why don't you add space in the separator field?

164 Posts
redback
10 years ago
0
Level 2

Hi Klas,

thanks for your answer. That would be a way. 

Problem: I already have data stored (Custom in intro field). Its a big work to change it manually in the SQL table, afterwards i changed the space in the separator field.

Is there a other solution.

Thanks a lot

10 years ago
3
Level 1

Hi redback,

My suggestion is to use a plugin " before render" in your content type / search type.

Let us assume that your checkbox field is called "my_checkbox". You have 2 different cases:

You can use the following code in the "before render" field:

$fields['my_checkbox']->value = str_replace( ', ', ',', $fields['my_checkbox']->value );


Regards,
Mehdi

164 Posts
redback
10 years ago
2
Level 2

Hi Mehdi, thanks a lot for your answer. I bought the "Code Pack (5 plug-ins)", but it has no effect. Here the setup:

Goal: Display checkbox field value, saved as "option1,option2,option3", like "option1, option2, option3" in content view.

Setup:

  1. Install "Code Pack (5 plug-ins)"
  2. Create a new field "gl_before_render_article_view" Type: BeforeRender and add it to mainbody in the Content Type
  3. Add the Code to the text area of "gl_before_render_article_view" (gl_anlass = my_checkbox), Mode: Free
    $fields['gl_anlass']->value = str_replace(',', ', ', $fields['gl_anlass']->value );

Tried as well to manipulate field output "gl_anlass" in other way, but is has no effect.

I m thankful for ideas

10 years ago
1
Level 3

Hi redback,

Can you set in your "before render" field this code to check the configuration of your checkbox field?

var_dump($fields['gl_anlass']->value);
var_dump($fields['gl_anlass']->text);

Regards,
Mehdi

164 Posts
redback
10 years ago
0
Level 4

Hallo Mehdi,

i getting this output:

string(38) "Therme Erding,Business,Urlaub,Fluggast" string(38) "Therme Erding,Business,Urlaub,Fluggast"

Thanks

175 Posts
webcastor
10 years ago
1
Level 1

A Q&D (quick&dirty) approach would be to do a phpMyAdmin SQL query such as

UPDATE `abcde_content` SET `gl_anlass` = replace(gl_anlass, ',', ', ') WHERE 1
164 Posts
redback
10 years ago
0
Level 2

Hi webcastor, thanks very much for the Q&D Lösung. Field is storage is custom (value is with other fields in the intro text column), therefore isn`t that easy. Best

10 years ago
1
Level 1

Hi,

In this case, try the code below:

$gl_anlass = $fields['gl_anlass']->value;
$gl_anlass = explode( ',', $gl_anlass );
foreach ( $gl_anlass as $elem ) {
 $elem = trim ($elem);
}
$gl_anlass = implode( ',', $gl_anlass );
$fields['gl_anlass']->value = str_replace( ',', ', ', $gl_anlass);

Regards,
Mehdi

164 Posts
redback
10 years ago
0
Level 2

Hi Mehdi,

thanks a lot for your effort putting the code up. I tried, but i didn't get it work. Maybe i did some false settings.

Anyway the solutions from _jrmo worked for me.

Thank for your help, redback

572 Posts
_jrmo
10 years ago
3
Level 1

Hi redback,

Another approach is to use this field (free) in your content or item view (whichever view you are using to display your output) - http://www.seblod.com/products/673

  • Install this typo plugin, and then on your checkbox field, select PHP String from the typo dropdown options.
  • Click the "+"
  • Choose the str_replace option
  • Enter a "," as the string you are searching for, and a ", " as the string you want to replace it with.
  • That will add a space after your commas in the output of your checkbox.

Thanks,

_jrmo

164 Posts
redback
10 years ago
2
Level 2

SOLUTION

Hello _jrmo,

thanks for your other approach and putting up the tutorial. This solution worked for me and is a easy way to manipulate the output of the checkbox field (String).

Thanks a lot and everybody else who helped on this topic.

Redback

8 years ago
0
Level 3

test getValue('what_kind_of_support');?>

looks like i cant get the checkbox value printed. is there way I can get the checkbox value as i can set the seperator from the checkbox field configuration

8 years ago
0
Level 3

Hi Redback,

Can you please let me know how you manage to print the values of the checkbox.

Thank you

8 years ago
0
Level 1

if the checkbox is not empty
(
for(i=0;i<checked count;i++)
{
echo field_name[i])-> getValue;
}
)

This is how i think it should work. Im not an expert

Get a VIP membership