I have created a web application which should take input from website and display it on a new page. I notice that my code is not getting called at all.
Routes file - I call localhost:9000 first. test method in Data controller is called which displays an input box and a submit button. Problem is on clicking submit, nothing happens
GET /data controllers.Data.test
GET /data/post controllers.Data.post
Model - what I enter in input should get mapped to User object using a form and get displayed in new page
case class User (name:String)
Controller code
object Data extends Controller {
val userForm = Form((mapping("name"->text))(User.apply)(User.unapply))
//this gets called for url localhost:9000/data
def test = Action {
Ok(views.html.dataIndex(None))
}
//PROBLEM - this should get called on clicking submit button but it doesn't get called
def post = Action { implicit request =>
println("in post")
val u:User = userForm.bindFromRequest().get
Ok(views.html.dataIndex(Some(u)))
}
}
View
@(u:Option[User])
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")">
<link rel="shortcut icon" type="image/png" href="@routes.Assets.at("images/favicon.png")">
<script src="@routes.Assets.at("javascripts/jquery-1.9.0.min.js")" type="text/javascript"></script>
</head>
<body>
@u match {
case Some(user) => {
<h1> You entered </h1>
<ul id="hardcode-list" >
<li>@user.name</li>
</ul>
}
case None => {
<h1>Feed User Data</h1>
<form action="/data/post" method="get">
<input type="text" name="name"/>
<input type="button" name="send" value="Submit"/>
</form>
}
}
</body>
</html>
What am I doing wrong?
Found the mistake. The button type should be 'submit'