Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8709723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:26:10+00:00 2026-06-13T04:26:10+00:00

I have some validation on input data which I really would prefer to handle

  • 0

I have some validation on input data which I really would prefer to handle in the controller code, because:

  1. It only applies in very specific circumstances, so cluttering the verifying function in the form definition would lower code cohesion.
  2. It produces collateral results which I need to use elsewhere in the controller.

What’s a clean way form producing a new Form like the one just bound with an additional (field or general) error message in the success branch of Form.fold?

To illustrate, I would like something like the (non-existent) Form.withError method I’m calling here:

val form= myForm.bindFromRequest
form.fold(
  errors => BadRequest(view(errors))
  {
    case(data, button) =>
      button match {
        case Some("save") =>
          val r= costlyFunction(data)
          if (r.isOk) {
            doSomethingWith(r)
            Ok(...)
          }
          else {
            val f= form.withError("my custom error")
            BadRequest(view(f))
          }
        case ...
      }
  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:26:11+00:00Added an answer on June 13, 2026 at 4:26 am

    Found it myself:

    val f= Form(form.mapping, form.data, 
      Seq(new play.api.data.FormError("error.key", "my error")), form.value)
    

    Apologies for the noise — leaving it here in case someone else gets stuck as I did.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some validation code which should display the max / min of a
i have a validation class which needs improving. If I require some custom validation
Does jQuery validation plugin have some dependencies? For example, I saw blogposts that said
I have decided to add some validation to my combobox, what I'm trying to
I have a form that submits to a third-party service that runs some validation.
i have a problem with my mvc3 application, i need to create some Validation
I have no idea why this doesn't work, but doing some validation functions and
I have the standard 'RequiredIf' attribute for some Conditional-Validation. My form and Model are
I have been asked to implement some email address validation on a web app
I have a service object that is responsible for some business logic validation. What

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.