# Drupal conditionally show/hide fields.
This needs to be done in a custom module. Anything that effects the CMS side of things needs to be done in a custom module. If you try to do it in `themes/custom/themname` it won't work. You can only do front end facing stuff there.
Referencing the code below.
1. Make a form array for the field you want to show hide.
2. In the form array do a `#states` array.
3. Add in the state you want to change.The example is using `invisible`.
4. Do a associative array. The left is a jquery-like selecter. The right is the state of that selector that triggers the `invisible` state.
```
// Hide name field when the anonymous checkbox is checked.
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#states' => array(
'invisible' => array(
':input[name="anonymous"]' => array('checked' => TRUE),
),
),
);
```
## Reference
[https://www.lullabot.com/articles/form-api-states](https://www.lullabot.com/articles/form-api-states)