<p>I assume you have basic knowledge about plugins and routing, if not I'll update my post in a few hours.. otherwise Your form could be</p>

<pre><code>&lt;!-- check if user submitted something --&gt;
{% if userExists is defined %}
    {% if userExists == true %}
        &lt;!-- user exists login --&gt;
        hello {{ user.name }}

        &lt;form method="post" accept-charset="UTF-8"&gt;
            {{ getCsrfInput() }}
            &lt;input type="hidden" name="action" value="users/login"&gt;

            &lt;h3&gt;&lt;label for="loginName"&gt;Username or email&lt;/label&gt;&lt;/h3&gt;
            &lt;input id="loginName" type="text" name="loginName"
                   value="{{ craft.session.rememberedUsername }}"&gt;

            &lt;h3&gt;&lt;label for="password"&gt;Password&lt;/label&gt;&lt;/h3&gt;
            &lt;input id="password" type="password" name="password"&gt;

            &lt;label&gt;
                &lt;input type="checkbox" name="rememberMe" value="1"&gt;
                Remember me
            &lt;/label&gt;

            &lt;input type="submit" value="Login"&gt;

            {% if errorMessage is defined %}
                &lt;p&gt;{{ errorMessage }}&lt;/p&gt;
            {% endif %}
        &lt;/form&gt;

        &lt;p&gt;&lt;a href="{{ url('forgotpassword') }}"&gt;Forget your password?&lt;/a&gt;&lt;/p&gt;

    {% else %}
        &lt;!-- user does not exist register --&gt;
        &lt;!-- snip see here for full content https://craftcms.com/docs/templating/user-registration-form --&gt;

    {% endif %}

{% else %}
    &lt;!-- parameter not set show search form --&gt;
    &lt;form method="post"&gt;
        &lt;input type="hidden" name="action" value="test/checkEmail"&gt;
        &lt;input type="text" name="email"&gt;
        &lt;input type="submit"&gt;
    &lt;/form&gt;
{% endif %}
</code></pre>

<p>And your controller </p>

<pre><code>public function actionCheckEmail(){
    $email = craft()-&gt;request-&gt;getParam('email');
    if($user = craft()-&gt;users-&gt;getUserByEmail($email)){
        // user registered
        $userExists = true;
    }else{
        $userExists = false;
    }
    craft()-&gt;urlManager-&gt;setRouteVariables([
        'userExists'    =&gt; $userExists,
        'user'          =&gt; $user
    ]);
}
</code></pre>

CC BY-SA 3.0
2017-12-13T23:31:09.513Z
Thanks Robin. I'm heading to bed now. I will take a good look tomorrow.
Jonathan Schofield
CC BY-SA 3.0
2017-12-13T23:21:31.660Z
2017-12-13T23:21:31.660Z
Robin Schambach
<p>How could I go about allowing a (not logged in) guest user to submit their email address, check behind the scenes if it belongs to a user account, and then return: </p>

<ol>
<li>A login form if it does</li>
<li>A registration form if it doesn't</li>
</ol>

<users>
Check if submitted email address belongs to a user account
# Check if submitted email address belongs to a user account

(Asked by: username_0 on 2017-12-13)

How could I go about allowing a (not logged in) guest user to submit their email address, check behind the scenes if it belongs to a user account, and then return:

1. A login form if it does
2. A registration form if it doesn't

**Tags:** users


---

## 1 answers

### Answer by username_1 on 2017-12-13. Score: 3

I assume you have basic knowledge about plugins and routing, if not I'll update my post in a few hours.. otherwise Your form could be

{% if userExists is defined %}
    {% if userExists == true %}
        
        hello {{ user.name }}

        
            {{ getCsrfInput() }}
            

            Username or email
            

            Password
            

            
                
                Remember me
            

            

            {% if errorMessage is defined %}
                {{ errorMessage }}
            {% endif %}
        

        Forget your password?

    {% else %}
        
        

    {% endif %}

{% else %}
    
    
        
        
        
    
{% endif %}

And your controller 
public function actionCheckEmail(){
    $email = craft()->request->getParam('email');
    if($user = craft()->users->getUserByEmail($email)){
        // user registered
        $userExists = true;
    }else{
        $userExists = false;
    }
    craft()->urlManager->setRouteVariables([
        'userExists'    => $userExists,
        'user'          => $user
    ]);
}

> **Comments:**
> **username_0**: Thanks Robin. I'm heading to bed now. I will take a good look tomorrow.  

---

