How can I make the website remember last shown form?

I have two forms inside one div:

  • Login form
  • Register form

Register form is hidden while login form is shown as default when you load the page. Im using js script to animate between those two forms by clicking anchor tag.

This causes problems for example while trying to register and you don't go through validation process correctly.

Hypothetical situation:

You've filled all the inputs, click submit button and it turns out that username you've provided is too short. The page will reload and it will show the default form again which is login form. You then again need to click "Register" a tag in order to switch between forms and then you see the error with validation.

I've been trying to read up about ways of doing that for days but seems like I can't specify my problem well enough in a short phrase. Can you guys explain what kind of method should I use and explain how to use it?

HTML:

<div class="login-page">
        <div class="form">
            <form class="register-form" method="POST">
                <input type="text" name="nick" placeholder="username"/>
                <input type="password" name="password1" placeholder="password"/>
                <input type="password" name="repassword" placeholder="repeat password"/>
                <input type="text" name="email" placeholder="e-mail adress"/>
                <button>Create</button>
                <p class="message">Already have an account? <a href="#">Log in!</a></p>
            </form>
            <form class="login-form" method="POST" action="login.php">
                <input type="text" name="login" placeholder="username"/>
                    <input type="password" name="password" placeholder="password"/>
                    <button>log in</button>
                    <p class="message">Don't have an account yet? <a id="createacc" href="#">Sign up!</a></p>
            </form>

JS:

$('.message a').click(function(){
$('form').animate({height: "toggle", opacity: "toggle"}, "slow"});

I want the website to remember which form you were filling before the page reloaded instead of always showing the default one (which is login form).

#javascript #html

2 Likes1.80 GEEK