<p>If you have a front end form for user registration then you should mark the fields as required in the CMS, you can then make use of Crafts form validation. </p>

<p>I had a project where we imported user data that didn't contain all required fields so needed to redirect users, after they signed in for the first time, to their profile page if data was missing.</p>

<p>I achieved this using a Plugin that contains a service that set a "status" for the current user. The service checked for several different fields and their values and also checked that the user had entered all required fields.</p>

<pre><code>public function setUserStatus( $user ){
    // Get whether user has agreed to current years terms
    $userAgreedToTerms = ( $user-&gt;getContent()-&gt;agreedCurrentYearsRules == 1 );

    // Use craft validate() function to find ask if user has completed all required fields in profile
    $userHasCompletedProfile = $user-&gt;validate() &amp;&amp; craft()-&gt;content-&gt;validateContent( $user );

    if ( $userAgreeToTerms ){
      $userStatus = 'AgreedToTerms';
    }
}
</code></pre>

<p>I then used the results of these checks to set a cookie with the "status" of the user.</p>

<pre><code>// Sets a cookie which is used to determine where the user should be re-directed to
$cookie = new HttpCookie( 'userStatus', $userStatus, [ 'expire' =&gt; time() + 10 ] );
craft()-&gt;request-&gt;getCookies()-&gt;add( $cookie-&gt;name, $cookie );
</code></pre>

<p>The function was run from the template using:</p>

<pre><code>{{ craft.pluginName.setUserStatus( currentUser ) }}
</code></pre>

<p>And the result of the check was used to redirect the user to the template I needed.</p>

<pre><code>{% set userStatus = craft.request.getCookie( 'userStatus' ) %}

{% if ( userStatus == 'needsToPay' ) and ( site_area != 'payment' ) %}
  {% redirect 'payment' %}
{% endif %}
</code></pre>

<p>Hopefully this provides you with enough to create something that works for your case.</p>

CC BY-SA 3.0
2016-05-24T18:13:37.500Z
That's really helpful Luke, thanks very much!
Ian Ebden
CC BY-SA 3.0
2016-05-24T11:05:26.827Z
2016-05-24T11:05:26.827Z
Luke Pearce
<p>I'm sure I've seen this documented somewhere but can't for the life of me find it. After login I need to check the user's profile for an empty field (e.g. phone number) and redirect them to a reminder to complete that field if empty. I guess this can be done via an intermediary page but I'm sure I saw a better solution somewhere. Any help?</p>

<login><user-profile><member>
How can I check a user has completed a field in their profile after log in?
# How can I check a user has completed a field in their profile after log in?

(Asked by: username_0 on 2016-05-24)

I'm sure I've seen this documented somewhere but can't for the life of me find it. After login I need to check the user's profile for an empty field (e.g. phone number) and redirect them to a reminder to complete that field if empty. I guess this can be done via an intermediary page but I'm sure I saw a better solution somewhere. Any help?

**Tags:** login, user-profile, member


---

## 1 answers

### Answer by username_1 on 2016-05-24. Score: 2 | Accepted answer

If you have a front end form for user registration then you should mark the fields as required in the CMS, you can then make use of Crafts form validation. 
I had a project where we imported user data that didn't contain all required fields so needed to redirect users, after they signed in for the first time, to their profile page if data was missing.
I achieved this using a Plugin that contains a service that set a "status" for the current user. The service checked for several different fields and their values and also checked that the user had entered all required fields.
public function setUserStatus( $user ){
    // Get whether user has agreed to current years terms
    $userAgreedToTerms = ( $user->getContent()->agreedCurrentYearsRules == 1 );

    // Use craft validate() function to find ask if user has completed all required fields in profile
    $userHasCompletedProfile = $user->validate() && craft()->content->validateContent( $user );

    if ( $userAgreeToTerms ){
      $userStatus = 'AgreedToTerms';
    }
}

I then used the results of these checks to set a cookie with the "status" of the user.
// Sets a cookie which is used to determine where the user should be re-directed to
$cookie = new HttpCookie( 'userStatus', $userStatus, [ 'expire' => time() + 10 ] );
craft()->request->getCookies()->add( $cookie->name, $cookie );

The function was run from the template using:
{{ craft.pluginName.setUserStatus( currentUser ) }}

And the result of the check was used to redirect the user to the template I needed.
{% set userStatus = craft.request.getCookie( 'userStatus' ) %}

{% if ( userStatus == 'needsToPay' ) and ( site_area != 'payment' ) %}
  {% redirect 'payment' %}
{% endif %}

Hopefully this provides you with enough to create something that works for your case.

> **Comments:**
> **username_0**: That's really helpful Luke, thanks very much!  

---

