# preHooks checkbox

**URL:** <https://community.modx.com/t/prehooks-checkbox/8272>\
**Category:** Random\
**Tags:** formit\
**Created:** [January 26, 2025, 12:01pm UTC](https://community.modx.com/t/prehooks-checkbox/8272 "2025-01-26T12:01:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vamp666](https://community.modx.com/letter_avatar_proxy/v4/letter/v/8baadc/32.png) [@vamp666](https://community.modx.com/u/vamp666)\
**Post date:** [January 26, 2025, 12:01pm UTC](https://community.modx.com/t/prehooks-checkbox/8272/1 "2025-01-26T12:01:38Z")

</div>

hi, help me add a checkbox to formIt  
i created preHook

```auto
$hook->setValue('color',json_encode(array('blue','red','green')));
return true;

```

and I go out of the form

```auto
<label>Color /[[!+fi.color]]</label>
<input type="checkbox" name="color[]" value="blue" [[!+fi.color:FormItIsChecked=`blue`]] > blue
<input type="checkbox" name="color[]" value="red" [[!+fi.color:FormItIsChecked=`red`]] > red
<input type="checkbox" name="color[]" value="green" [[!+fi.color:FormItIsChecked=`green`]] > green

```

but the checkbox is not selected  
and in [[!+fi.color]]  
it displays ‘[“blue”,“red”,“green”]’  
how to make them become Checked

formit 5.0.1-pl  
modx 3.0.5-pl

---

<div class="post-metadata">

**Author:** ![halftrainedharry](https://community.modx.com/user_avatar/community.modx.com/halftrainedharry/32/1063_2.png) [@halftrainedharry](https://community.modx.com/u/halftrainedharry)\
**Post date:** [January 26, 2025, 12:21pm UTC](https://community.modx.com/t/prehooks-checkbox/8272/2 "2025-01-26T12:21:16Z")

</div>

I can’t reproduce this issue.  
It seems to work correctly when I test it.

---

<div class="post-metadata">

**Author:** ![vamp666](https://community.modx.com/letter_avatar_proxy/v4/letter/v/8baadc/32.png) [@vamp666](https://community.modx.com/u/vamp666)\
**Post date:** [January 26, 2025, 2:22pm UTC](https://community.modx.com/t/prehooks-checkbox/8272/4 "2025-01-26T14:22:42Z")

</div>

Doesn’t work if used FENOM

```auto
{'!FormIt' | snippet : [
                      'preHooks' => 'foreach'
                    ]}

```

if you use standard output everything works

```auto
[[!FormIt?
                    &preHooks=`foreach`
                 ]]

```

---

<div class="post-metadata">

**Author:** ![halftrainedharry](https://community.modx.com/user_avatar/community.modx.com/halftrainedharry/32/1063_2.png) [@halftrainedharry](https://community.modx.com/u/halftrainedharry)\
**Post date:** [January 26, 2025, 2:37pm UTC](https://community.modx.com/t/prehooks-checkbox/8272/5 "2025-01-26T14:37:42Z")

</div>

I still can’t reproduce this.  
When I test it, it does work. Even when using Fenom for the _FormIt_ snippet call.
