Material Design Lite form button doesn't submit anything

3.1k Views Asked by At

I am rather new to CSS and might miss some basic thing. I get the code for HTML form from tutorial site for Material Design Lite but it doesn't send any HTTP request.

What do I miss?

<div class="mdl-layout mdl-js-layout mdl-color--grey-100">
    <main class="mdl-layout__content">
        <div class="mdl-card mdl-shadow--6dp">
            <div class="mdl-card__title mdl-color--primary mdl-color-text--white">
                <h2 class="mdl-card__title-text">Acme Co.</h2>
            </div>
        <div class="mdl-card__supporting-text">
                <form action="foo.html">
                    <div class="mdl-textfield mdl-js-textfield">
                        <input class="mdl-textfield__input" type="text" id="username" />
                        <label class="mdl-textfield__label" for="username">Username</label>
                    </div>
                    <div class="mdl-textfield mdl-js-textfield">
                        <input class="mdl-textfield__input" type="password" id="userpass" />
                        <label class="mdl-textfield__label" for="userpass">Password</label>
                    </div>
                </form>
            </div>
            <div class="mdl-card__actions mdl-card--border">
                <button class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect">Log in</button>
            </div>
        </div>
    </main>
</div>
3

There are 3 best solutions below

2
Matteo Scardamaglia On

I think you got wrong 100%.

Why?

HTML, CSS and JavaScript can't send HTTP Request.

You can use Ajax, PHP or every programming language that can send HTTP request you want.

0
Hashaam Haider On

<button class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect" type="submit" name="action">Submit</button>use this, you are using a simple button, but a php form accepts a submit type button with an action.

2
sergvb On

Put your <Button> inside <form></form> tag.

Like this:

<div class="mdl-layout mdl-js-layout mdl-color--grey-100">
    <main class="mdl-layout__content">
        <div class="mdl-card mdl-shadow--6dp">
            <div class="mdl-card__title mdl-color--primary mdl-color-text--white">
                <h2 class="mdl-card__title-text">Acme Co.</h2>
            </div>
        <div class="mdl-card__supporting-text">
                <form action="foo.html">
                    <div class="mdl-textfield mdl-js-textfield">
                        <input class="mdl-textfield__input" type="text" id="username" />
                        <label class="mdl-textfield__label" for="username">Username</label>
                    </div>
                    <div class="mdl-textfield mdl-js-textfield">
                        <input class="mdl-textfield__input" type="password" id="userpass" />
                        <label class="mdl-textfield__label" for="userpass">Password</label>
                    </div>
                    <div class="mdl-card__actions mdl-card--border">
                        <button class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect" type="submit" name="login">Log in</button>
                    </div>
                </form>
            </div>
        </div>
    </main>
</div>