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>



        }
4

1 回答 1

1

例如,您可以使用表单助手以这种方式打印出您的错误:

@form.globalError.map { error =>
<p class="error">
    @error.message
</p>
}
于 2013-02-08T17:55:29.123 回答