# How can I force users to fill in a custom field when it’s empty

**URL:** https://meta.discourse.org/t/how-can-i-force-users-to-fill-in-a-custom-field-when-it-s-empty/225929
**Category:** Development
**Created:** [May 2, 2022, 10:11pm UTC](https://meta.discourse.org/t/how-can-i-force-users-to-fill-in-a-custom-field-when-it-s-empty/225929 "2022-05-02T22:11:40Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Jacky2](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jacky2/32/243936_2.png) [@Jacky2](https://meta.discourse.org/u/Jacky2)
#### Post date: [May 2, 2022, 10:11pm UTC](https://meta.discourse.org/t/how-can-i-force-users-to-fill-in-a-custom-field-when-it-s-empty/225929/1 "2022-05-02T22:11:40Z")

</div>

Hello Discourse community!  
I’m new to Discourse and trying to use my few ruby ​​knowledge. Thanks for your help !  
Here is my project :  
I created custom fields to get to know a new user better and now I want to update the custom field for old users.  
I want to display my question at login if the field is empty.  
If I understand Discourse correctly, I need to code a plugin.  
Do you have a tip or an example in mind for this first challenge?  
Thanks in advance !

---

<div class="post-metadata">

### Author: ![Jacky2](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jacky2/32/243936_2.png) [@Jacky2](https://meta.discourse.org/u/Jacky2)
#### Post date: [May 2, 2022, 10:32pm UTC](https://meta.discourse.org/t/how-can-i-force-users-to-fill-in-a-custom-field-when-it-s-empty/225929/2 "2022-05-02T22:32:02Z")

</div>

In rails console, i use

```plaintext
UserCustomField.where.not(value: [nil])

```

to find users who have already replied but for the rest I dry…  
How to get users who haven’t answered the question?  
Guess I’ll need to figure this out later.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [May 2, 2022, 11:20pm UTC](https://meta.discourse.org/t/how-can-i-force-users-to-fill-in-a-custom-field-when-it-s-empty/225929/3 "2022-05-02T23:20:49Z")

</div>

Two suggestions:

- Consider asking how to solve your problem (getting users to fill the in the field). The user wizard plugin might be a solution?

- Move this to #Development and ask there. I think that it might be possible with a theme component if the values are in serializer.

For either, change he subject to something like “how can I force users to fill in a custom field when it’s empty”

I don’t have a very good answer, though. 🤷

---

<div class="post-metadata">

### Author: ![Simon\_Manning](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon_manning/32/198596_2.png) [@Simon\_Manning](https://meta.discourse.org/u/Simon_Manning)
#### Post date: [May 2, 2022, 11:28pm UTC](https://meta.discourse.org/t/how-can-i-force-users-to-fill-in-a-custom-field-when-it-s-empty/225929/4 "2022-05-02T23:28:02Z")

</div>

> [@Jacky2](#):
>
> How to get users who haven’t answered the question?

To that specific question, assuming that an unanswered question will be NULL in the database, you can just replace `where.not(value: [nil])` with `where(value: nil)`.

You can also use `where(value: [nil, ""])`, which is equivalent to `WHERE (something.value IS NULL OR something.value = "")` in SQL, to search for an empty string or NULL. I’m not sure which it’s likely to be or if it’s likely to change (from NULL to “”) if a user submits an empty field.

---

<div class="post-metadata">

### Author: ![Jacky2](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jacky2/32/243936_2.png) [@Jacky2](https://meta.discourse.org/u/Jacky2)
#### Post date: [May 3, 2022, 7:05am UTC](https://meta.discourse.org/t/how-can-i-force-users-to-fill-in-a-custom-field-when-it-s-empty/225929/5 "2022-05-03T07:05:18Z")

</div>

Thanks @pfaffman. I will follow your advice. 👍

---

<div class="post-metadata">

### Author: ![Jacky2](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jacky2/32/243936_2.png) [@Jacky2](https://meta.discourse.org/u/Jacky2)
#### Post date: [May 3, 2022, 7:07am UTC](https://meta.discourse.org/t/how-can-i-force-users-to-fill-in-a-custom-field-when-it-s-empty/225929/6 "2022-05-03T07:07:01Z")

</div>

Thanks @Simon_Manning for this precision. That will help me a lot !

---

<div class="post-metadata">

### Author: ![Jacky2](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jacky2/32/243936_2.png) [@Jacky2](https://meta.discourse.org/u/Jacky2)
#### Post date: [May 4, 2022, 6:00pm UTC](https://meta.discourse.org/t/how-can-i-force-users-to-fill-in-a-custom-field-when-it-s-empty/225929/7 "2022-05-04T18:00:25Z")

</div>

This plugin is great. Thanks @pfaffman

---

<div class="post-metadata">

### Author: ![Jacky2](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jacky2/32/243936_2.png) [@Jacky2](https://meta.discourse.org/u/Jacky2)
#### Post date: [May 6, 2022, 8:12am UTC](https://meta.discourse.org/t/how-can-i-force-users-to-fill-in-a-custom-field-when-it-s-empty/225929/8 "2022-05-06T08:12:48Z")

</div>

Thanks again guys. Custom wizard plugin works very well 👍
