播放框架2表单 - 无法获取错误消息

时间:2013-02-08 09:24:45

标签: scala playframework-2.0

如果表单为空,则错误永远不会显示只是呈现空白页:(可能是什么错误?

只想显示上传文件的表单和额外的表单输入,无法同时找到有关表单数据和上传文件的任何好文档。

def aboutUsImages = Action { implicit request =>
        val getall = AboutImages.findAll
        Ok(views.html.adminpages.aboutusimages(getall))
    }


  def editUsImages(id: Int) = Action { implicit req =>

    val getbyid = AboutImages.findById(id)
    val text = getbyid(0).name
    val dummyform = Form(ignored(("dummy")))
    Ok(views.html.adminpages.aboutusimgsForm(dummyform, id, text))
  }


  def upload() = Action(parse.multipartFormData) { implicit request =>
    val dump = ""
    val form = Form(tuple(
      "id" -> nonEmptyText,
      "name" -> text,
      "image" -> ignored(request.body.file("image")).
        verifying("File missing", _.isDefined)))
    form.bindFromRequest.fold(
      formWithErrors => {
        Ok(views.html.adminpages.aboutusimgsForm(formWithErrors, request.id, dump))
      },
      value => Ok
    )
  } 

和表格:

@helper.form(action = routes.AboutUsImages.upload(),'enctype -> "multipart/form-data") {
             <input type="hidden" name="id" value="@id">
            <input type="text" name="name" value="@text">
            @helper.inputFile(form("image"))


            <div class="actions">
                <input type="submit" value="Save Setting" class="btn primary"> or
                <a href="@routes.AboutUsImages.aboutUsImages()" class="btn">Cancel</a>
            </div>



        }

1 个答案:

答案 0 :(得分:1)

您可以使用表单助手以此方式打印出错误:

@form.globalError.map { error =>
<p class="error">
    @error.message
</p>
}