title: Play Framework: access form when validation succeeds
body: <p>I have a form submission in Play 2.6 in which most validation can't be performed up front. The web application sends the submitted form data to a backend in another project, which will throw a GrammarException for most user errors. How can I propagate an error message and the original Form values back to the view</p>
  
  <p>This is similar to <a href="https://stackoverflow.com/questions/28221873/how-to-access-my-forms-properties-when-validation-fails-in-the-fold-call">How to access my forms properties when validation fails in the fold call?</a>, but I need the form values on success.</p>
  
  <pre><code>form.bindFromRequest().fold(
    formWithErrors =&gt; {
      BadRequest(myView(newForm = formWithErrors)(request))
    },
    data =&gt; try {
      val results = MyBackend.build(data) // time-consuming
      Ok(views.html.myView(results)
    } catch { // catches most user errors
      case e: GrammarException =&gt;
        val submittedForm = ....? //
        val formWithErrors = submittedForm.withGlobalError(e.getMessage)
        BadRequest(myView(newForm = formWithErrors)(request))
    }
  )
  </code></pre>