Big_Data
Big_Data

Reputation: 322

play framework--- HTML submit button controller code

what more code should i use for play framework in intellij... I just need to display a welcome to homepage body(LoginSuccess.scala.html) page after clicking submit button

I want to display a message like welcome to HomePage

<!DOCTYPE html>
<html>
<body>
welcome to homepage
</body>
</html>

by using this code after clicking submit button.. should i write any controller code for it. if so please answer here

<!DOCTYPE html>
<html>
<body>
Username<input type="text" name = "uname">
password<input type="password" name="pword"
<input type="submit" value ="submit"
</body>
</html>

Upvotes: 0

Views: 757

Answers (1)

Dragomir Kolev
Dragomir Kolev

Reputation: 1108

To redirect to the home page you need a controller that renders it.

For instance if I have HomeController and a function inside it that does something like:

public Result welcome() {
        return ok(views.html.index.render());
    }

Then you would have to set up your routes file to do something like

GET     /                      controllers.HomeController.welcome()

Once that is done then you can put do something like this on your button code:

<input onclick="window.location.href='@routes.HomeController.welcome()'"></input>

I would suggest using a javascript function to redirect to a page if you are going to be using an input html object but if you want you can also do something like this

<a href="@routes.HomeController.welcome()">
     <div class="my-button">Button</div>
</a>

Then you can style the class my-button to make it look like a button.

I hope that answers your question.

Upvotes: 1

Related Questions