<p>From the code</p>

<pre><code>// Don't validate required custom fields if it's public registration
if (!$thisIsPublicRegistration) {
    $user-&gt;setScenario(Element::SCENARIO_LIVE);
}
</code></pre>

<p>You have to create a custom controller </p>

CC BY-SA 3.0
2018-04-26T23:45:43.853Z
Oh wow this used to work in Craft 2. Bummer. I'm not familiar with how to create a controller. Would that be done with a plugin?
Clay Kilby
CC BY-SA 3.0
2018-04-28T18:52:09.023Z
@ClayKilby Or in a module... You should read the docs or ask a new question
Robin Schambach
CC BY-SA 3.0
2018-04-26T21:51:14.237Z
2018-04-26T21:51:14.237Z
Robin Schambach
<p><strong>Craft 3.7+</strong></p>
<p>Hooray, there is a new setting in 3.7 for this:
<a href="https://github.com/craftcms/cms/issues/4229" rel="nofollow noreferrer">https://github.com/craftcms/cms/issues/4229</a></p>
<p><strong>Craft 3.0 - 3.6.x</strong></p>
<p>Ran into this issue. I have a site (updated it from Craft 2) where I need the custom fields to be validated on the public registration form.</p>
<p>I copied the entire controller from <code>vendor/craftcms/cms/src/controllers/UsersController.php</code> into my module (created with <a href="https://pluginfactory.io" rel="nofollow noreferrer">https://pluginfactory.io</a>), adjusted the namespace and removed the conditional.</p>
<pre><code>namespace modules\modulehandle\controllers;
use modules\modulehandle\ModuleHandle;

// Instead of:
// if (!$thisIsPublicRegistration) {
//    $user-&gt;setScenario(Element::SCENARIO_LIVE);
// }

$user-&gt;setScenario(Element::SCENARIO_LIVE);
</code></pre>
<p>This feels awful. Duplicating an entire controller, just to remove one conditional. I’ll miss updates to the controller and everything. An option in <code>general.php</code> would have solved this pretty great. I’ll ask the Craft folks if there is any chance that this will become a setting.</p>

CC BY-SA 4.0
2019-05-07T19:59:13.090Z
Posted a feature request to GitHub: https://github.com/craftcms/cms/issues/4229
medoingthings
CC BY-SA 4.0
2019-05-07T19:37:29.213Z
2021-06-23T10:19:09.813Z
2021-06-23T10:19:09.813Z
medoingthings
<p>I've built a front end user registration form and everything is working well with it except that it's not showing errors for my custom fields. They're set as required in the CP, but the form submits even if they aren't filled in. When the standard required fields aren't filled in the for returns an error but none for the custom fields.</p>

<p>I understand first and last name can't be required. In the example below my custom required fields are participantPhone and participantCity.</p>

<pre><code>&lt;form method="post" accept-charset="UTF-8"&gt;
  &lt;div class="form-group signup-form"&gt;
      {{ csrfInput() }}
      &lt;input type="hidden" name="action" value="users/save-user"&gt;
      {{ redirectInput('sign-up-ty') }}

      {% macro errorList(errors) %}
        {% if errors %}
          &lt;ul class="errors"&gt;
            {% for error in errors %}
              &lt;li&gt;{{ error }}&lt;/li&gt;
            {% endfor %}
          &lt;/ul&gt;
        {% endif %}
      {% endmacro %}

      {% from _self import errorList %}

      &lt;input id="username" class="form-control" type="text" name="username" {%- if user is defined %} value="{{ user.username }}"{% endif -%} placeholder="username"&gt;

      {% if user is defined %}
        {{ errorList(user.getErrors('username')) }}
      {% endif %}

      &lt;input id="firstName" class="form-control" type="text" name="firstName" {%- if user is defined %} value="{{ user.firstName }}"{% endif -%} placeholder="first name"&gt;

      &lt;input id="lastName" class="form-control" type="text" name="lastName" {%- if user is defined %} value="{{ user.lastName }}"{% endif -%} placeholder="last name"&gt;

      &lt;input id="email" class="form-control" type="text" name="email"{%- if user is defined %} value="{{ user.email }}"{% endif %} placeholder="email"&gt;

      {% if user is defined %}
        {{ errorList(user.getErrors('email')) }}
      {% endif %}

      &lt;input id="password" class="form-control" type="password" name="password" placeholder="password"&gt;

      {% if user is defined %}
        {{ errorList(user.getErrors('password')) }}
      {% endif %}

      &lt;input id="participantPhone" class="form-control" type="text" name="fields[participantPhone]" {%- if user is defined %} value="{{ user.participantPhone }}"{% endif -%} placeholder="phone"&gt;

      {% if user is defined %}
        {{ errorList(user.getErrors('participantPhone')) }}
      {% endif %}

      &lt;input id="participantCity" class="form-control" type="text" name="fields[participantCity]" {%- if user is defined %} value="{{ user.participantCity }}"{% endif -%} placeholder="city"&gt;

      {% if user is defined %}
        {{ errorList(user.getErrors('participantCity')) }}
      {% endif %}

      &lt;input id="register-button" class="btn btn-outline-primary" type="submit" value="Register"&gt;
    &lt;/div&gt;
  &lt;/form&gt;
</code></pre>

<craft3>
Craft 3 User Registration form errors not showing for custom fields
# Craft 3 User Registration form errors not showing for custom fields

(Asked by: username_0 on 2018-04-26)

I've built a front end user registration form and everything is working well with it except that it's not showing errors for my custom fields. They're set as required in the CP, but the form submits even if they aren't filled in. When the standard required fields aren't filled in the for returns an error but none for the custom fields.
I understand first and last name can't be required. In the example below my custom required fields are participantPhone and participantCity.

  
      {{ csrfInput() }}
      
      {{ redirectInput('sign-up-ty') }}

      {% macro errorList(errors) %}
        {% if errors %}
          
            {% for error in errors %}
              {{ error }}
            {% endfor %}
          
        {% endif %}
      {% endmacro %}

      {% from _self import errorList %}

      

      {% if user is defined %}
        {{ errorList(user.getErrors('username')) }}
      {% endif %}

      

      

      

      {% if user is defined %}
        {{ errorList(user.getErrors('email')) }}
      {% endif %}

      

      {% if user is defined %}
        {{ errorList(user.getErrors('password')) }}
      {% endif %}

      

      {% if user is defined %}
        {{ errorList(user.getErrors('participantPhone')) }}
      {% endif %}

      

      {% if user is defined %}
        {{ errorList(user.getErrors('participantCity')) }}
      {% endif %}

**Tags:** craft3

---

## 2 answers

### Answer by username_1 on 2018-04-26. Score: 2 | Accepted answer

From the code
// Don't validate required custom fields if it's public registration
if (!$thisIsPublicRegistration) {
    $user->setScenario(Element::SCENARIO_LIVE);
}

You have to create a custom controller

> **Comments:**
> **username_0**: Oh wow this used to work in Craft 2. Bummer. I'm not familiar with how to create a controller. Would that be done with a plugin?  
> **username_1**: @ClayKilby Or in a module... You should read the docs or ask a new question  

---

### Answer by username_2 on 2019-05-07. Score: 3

Craft 3.7+
Hooray, there is a new setting in 3.7 for this:
https://github.com/craftcms/cms/issues/4229
Craft 3.0 - 3.6.x
Ran into this issue. I have a site (updated it from Craft 2) where I need the custom fields to be validated on the public registration form.
I copied the entire controller from vendor/craftcms/cms/src/controllers/UsersController.php into my module (created with https://pluginfactory.io), adjusted the namespace and removed the conditional.
namespace modules\modulehandle\controllers;
use modules\modulehandle\ModuleHandle;

// Instead of:
// if (!$thisIsPublicRegistration) {
//    $user->setScenario(Element::SCENARIO_LIVE);
// }

$user->setScenario(Element::SCENARIO_LIVE);

This feels awful. Duplicating an entire controller, just to remove one conditional. I’ll miss updates to the controller and everything. An option in general.php would have solved this pretty great. I’ll ask the Craft folks if there is any chance that this will become a setting.

> **Comments:**
> **username_2**: Posted a feature request to GitHub: https://github.com/craftcms/cms/issues/4229  

---

