i have created a simply login submit form using playframework and scala without connecting any database.
my application.scala
which is my controller i have written the code
import play.api._
import play.api.mvc._
import play.api.data._
import play.api.data.Forms._
import play.api.mvc.Request
import views.html._
case class Userdata(email:String,password:String)
object Application extends Controller {
case class Userdata(email:String,password:String)
val userForm = Form(
mapping(
"email" -> text,
"password" -> text
)(Userdata.apply)(Userdata.unapply)
)
def usercheck = Action{ implicit request=>
userForm.bindFromRequest.fold(
formWithErrors => BadRequest(views.html.login(formWithErrors)),
Userdata => { Ok(views.html.index("congrates"))}
)}
def index() = Action {
implicit request=>
Ok(views.html.login(userForm))
}
and my view template is login.scala.html
..
@(form: Form[(String,String)])
@import helper._
@form(routes.Application.usercheck){
<form class=frmuuser>
<input type=text placeholder=email id='emailid'>
<input type=password placeholder=password id='pwd'>
<input type=submit value=login id='enter'>
</form>
}
but it is not working and giving me error
type mismatch; found : play.api.data.Form[controllers.Application.Userdata] required: play.api.data.Form[(String, String)]
in this line of contoller
formWithErrors => BadRequest(views.html.login(formWithErrors)),
what is soultion for my problem??
Few points to note:
Userdata
outside the Application controller. That is move it inside controller package.Try this.
Application.scala
: only oneUserdata
case class definition ( you had two of these classes defined )login.scala.html
: useUserdata
instead of(String, String)