<p>If you have access to jQuery in your project, you can <a href="https://gist.github.com/olivierbon/6c9013fa9b2841bb954909070c02e236" rel="nofollow noreferrer">do this</a>.</p>

<p>Change the name of your checkboxes so craft doesn't look at them when the form gets posted and have a hidden input (named inline with your form) that you populate using using js.</p>

<p>This uses jQuery but you can convert to Javascript if needed. It's not perfect but it might get you on the way :)</p>

CC BY-SA 4.0
2019-02-01T17:39:44.503Z
Yes, I am using jQuery on my site. Where would I put the actual fieldname of the Craft field 'fields[logGeneral_logInputIndications]' ?  I'm assuming I put the jQuery as a hidden form field?
Lori
CC BY-SA 4.0
2019-02-01T17:53:31.117Z
I'm getting the following as my submitted value: `function updateP() {
  var text = '';
  $(`
Lori
CC BY-SA 4.0
2019-02-01T18:01:09.710Z
It's a front end form but only logged in members can see and submit the form.  Yes, I'm still working on this.
Lori
CC BY-SA 4.0
2019-02-01T18:02:08.813Z
I'm using that basic code, but it's not a guest entry submission form.
Lori
CC BY-SA 4.0
2019-02-01T18:30:23.673Z
For some reason, I still can't get it to work.  Here's a the code I'm using: https://codepen.io/anon/pen/exWOQq
Lori
CC BY-SA 4.0
2019-02-01T18:41:47.523Z
Still no go. I'm sorry.  I really appreciate your help but I must be doing something wrong. When I paste the jQuery code into the codepen I got this error: `index.js: Unexpected token, expected } (10:4)`
Lori
CC BY-SA 4.0
2019-02-01T18:46:39.847Z
Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/89133/discussion-between-lori-and-olivier-bon).
Lori
CC BY-SA 4.0
2019-02-20T18:33:46.750Z
@oliver-bon - Sorry for the long delay, but I was able to get the latest code you sent working.  Thank you so very much!
Lori
CC BY-SA 4.0
2019-02-20T18:35:56.010Z
@Lori hey, that's cool :) Glad it worked. Mark it as a response if you can so it helps others :)
Oli
CC BY-SA 4.0
2019-02-20T18:39:17.243Z
Anyone looking for the solution, @oliver-bon provided me with code solution in our chat discussion which can be found here: https://chat.stackexchange.com/rooms/89133/discussion-between-lori-and-olivier-bon
Lori
CC BY-SA 4.0
2019-02-01T17:18:34.210Z
2019-02-01T19:10:33.623Z
2019-02-01T19:10:33.623Z
Oli
<p>If you need to do this in a twig template, the <code>join</code> filter will do the job.</p>

<p>Use <code>{{ yourCheckboxesValues|join(', ') }}</code> to print something like that : <code>value1, value2, value3</code>.</p>

CC BY-SA 4.0
2019-02-01T16:43:09.547Z
I may be misunderstanding your response @Maxime but how would I capture the joined value and submit that to my database entry? I’m wondering if I need to use a variable to collect the values and then submit the variable to the form field in the database.
Lori
CC BY-SA 4.0
2019-02-01T17:22:33.693Z
Do you use a plugin or a custom module to submit your form ?
Maxime Lafrenière
CC BY-SA 4.0
2019-02-01T17:40:25.350Z
No, I am not using any custom module to submit the form.  It's just a regular form.
Lori
CC BY-SA 4.0
2019-02-01T18:16:16.223Z
Are you submitting via ajax? Is so the answer of @Oliver Bon is a more efficient way to achieve your goal.

If not; you can also create a custom module and hook a function to transform your field data before its saved on your entry (or sent by mail?)
Maxime Lafrenière
CC BY-SA 4.0
2019-02-01T18:18:43.060Z
No, I'm not currently submitting using Ajax.  I'm just submitting it normally. Sounds like the join option you submitted requires additional module which I don't have the skills to do.  But thank you so much for your input.  I was just wondering if I was missing something with the join filter.
Lori
CC BY-SA 4.0
2019-02-01T18:24:47.587Z
`join` is a builtin Twig filter
Maxime Lafrenière
CC BY-SA 4.0
2019-02-01T18:27:55.900Z
Yes, that's why I was wondering if I could use the `join` filter to output to a variable and then submit the variable to the Craft form field.
Lori
CC BY-SA 4.0
2019-02-02T14:33:04.807Z
Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/89155/discussion-between-maxime-lafreniere-and-lori).
Maxime Lafrenière
CC BY-SA 4.0
2019-02-01T16:36:57.360Z
2019-02-01T16:36:57.360Z
Maxime Lafrenière
<p>I have a front end form with multiple checkboxes. Is it possible to convert the checkbox values from an array to a string before it's submitted to the database?</p>

<p>I want to save the checkbox values into a PlainText Craft field in the database.</p>

<p>If I try to submit the front end form checkbox values into a PlainText field currently, I get the error: <code>trim() expects parameter 1 to be string, array given</code></p>

<p>It looks like perhaps using the <code>join</code> or <code>merge</code> filter may accomplish this but I'm not sure. </p>

<form><checkboxes>
Convert checkbox values from an array to a string
# Convert checkbox values from an array to a string

(Asked by: username_0 on 2019-02-01)

I have a front end form with multiple checkboxes. Is it possible to convert the checkbox values from an array to a string before it's submitted to the database?

I want to save the checkbox values into a PlainText Craft field in the database.

If I try to submit the front end form checkbox values into a PlainText field currently, I get the error: `trim() expects parameter 1 to be string, array given`

It looks like perhaps using the `join` or `merge` filter may accomplish this but I'm not sure.

**Tags:** form, checkboxes

---

## 2 answers

### Answer by username_1 on 2019-02-01. Score: 1 | Accepted answer

If you have access to jQuery in your project, you can [do this](https://gist.github.com/olivierbon/6c9013fa9b2841bb954909070c02e236).

Change the name of your checkboxes so craft doesn't look at them when the form gets posted and have a hidden input (named inline with your form) that you populate using using js.

This uses jQuery but you can convert to Javascript if needed. It's not perfect but it might get you on the way :)

> **Comments:**
> **username_0**: Yes, I am using jQuery on my site. Where would I put the actual fieldname of the Craft field 'fields[logGeneral_logInputIndications]' ?  I'm assuming I put the jQuery as a hidden form field?  
> **username_0**: I'm getting the following as my submitted value: `function updateP() {   var text = '';   $(`  
> **username_0**: It's a front end form but only logged in members can see and submit the form.  Yes, I'm still working on this.  
> **username_0**: I'm using that basic code, but it's not a guest entry submission form.  
> **username_0**: For some reason, I still can't get it to work.  Here's a the code I'm using: https://codepen.io/anon/pen/exWOQq  
> **username_0**: Still no go. I'm sorry.  I really appreciate your help but I must be doing something wrong. When I paste the jQuery code into the codepen I got this error: `index.js: Unexpected token, expected } (10:4)`  
> **username_0**: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/89133/discussion-between-lori-and-olivier-bon).  
> **username_0**: @oliver-bon - Sorry for the long delay, but I was able to get the latest code you sent working.  Thank you so very much!  
> **username_1**: @Lori hey, that's cool :) Glad it worked. Mark it as a response if you can so it helps others :)  
> **username_0**: Anyone looking for the solution, @oliver-bon provided me with code solution in our chat discussion which can be found here: https://chat.stackexchange.com/rooms/89133/discussion-between-lori-and-olivier-bon  

---

### Answer by username_2 on 2019-02-01. Score: 1

If you need to do this in a twig template, the `join` filter will do the job.

Use `{{ yourCheckboxesValues|join(', ') }}` to print something like that : `value1, value2, value3`.

> **Comments:**
> **username_0**: I may be misunderstanding your response @Maxime but how would I capture the joined value and submit that to my database entry? I’m wondering if I need to use a variable to collect the values and then submit the variable to the form field in the database.  
> **username_2**: Do you use a plugin or a custom module to submit your form ?  
> **username_0**: No, I am not using any custom module to submit the form.  It's just a regular form.  
> **username_2**: Are you submitting via ajax? Is so the answer of @Oliver Bon is a more efficient way to achieve your goal.  If not; you can also create a custom module and hook a function to transform your field data before its saved on your entry (or sent by mail?)  
> **username_0**: No, I'm not currently submitting using Ajax.  I'm just submitting it normally. Sounds like the join option you submitted requires additional module which I don't have the skills to do.  But thank you so much for your input.  I was just wondering if I was missing something with the join filter.  
> **username_2**: `join` is a builtin Twig filter  
> **username_0**: Yes, that's why I was wondering if I could use the `join` filter to output to a variable and then submit the variable to the Craft form field.  
> **username_2**: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/89155/discussion-between-maxime-lafreniere-and-lori).  

---

