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 9307869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T00:29:17+00:00 2026-06-19T00:29:17+00:00

I am new to scala and type-safe languages so I could be overlooking something

  • 0

I am new to scala and type-safe languages so I could be overlooking something basic. That said here’s my problem.

Goal: I want to submit a form that is just one text input, and does not mirror my case class. It is going to end up as type: String

Issue: Can’t get into success from fold

I have a form on the frontend that I opted to write in html instead of play’s form helpers (willing to change if this is the issue)

<form method="POST" action="@routes.Application.shorten()">
  <input id="urlLong" name="urlLong" type="text" placeholder="http://www.google.com/" class="span4"/>
  <div class="form-actions">
    <button type="reset" class="btn">Reset</button>
    <button type="submit" class="btn btn-primary pull-right"><span class="icon-random"></span> Shrtn It!</button>
  </div>
</form>

The controller that is handling the post action looks like this:

import ...

object Application extends Controller {

  val newUrlForm = Form(
    "urlLong" -> text
  )

  def shorten = Action { implicit request =>
    val urlLong = newUrlForm.bindFromRequest.get

    newUrlForm.fold(
      hasErrors = { form =>
        val message = "Somethings gone terribly wrong"
        Redirect(routes.Application.dash()).flashing("error" -> message)
    },

    success = { form =>
      val message = "Woot it was successfully added!"
      Redirect(routes.Application.dash()).flashing("success" -> message)
    }
  }
  ...
}

I was trying to follow / modify the tutorial in the Play for Scala book, but they match their form to a case class, and Play’s tutorial is a bit off from my use case as well. Along with your answer if you could include how you figured it out, that would be really useful so I can troubleshoot on my own better.

  • http://www.playframework.com/documentation/2.0/ScalaForms
  • http://www.playframework.com/documentation/api/2.0/scala/index.html#play.api.data.Forms$

Also if it matters I am using intellij idea as my ide

  • 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-19T00:29:19+00:00Added an answer on June 19, 2026 at 12:29 am

    You need to call the fold method on form.bindFromRequest. From the documentation > Handling binding failure

    loginForm.bindFromRequest.fold(
      formWithErrors => // binding failure, you retrieve the form containing errors,
      value => // binding success, you get the actual value 
    )
    

    Also you can use the single Mapping construct for a single field

    Form(
      single(
        "email" -> email
      )
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to scala and most functional languages and I'm currently trying to factor
I'm new to Scala and don't know Java. I want to create a jar
I'm new to Scala, so I may be off base on this, I want
I am new to Scala, just started learning, so this is basic beginner question.
I'm new to Scala... Here's the code: def ack2(m: BigInt, n: BigInt): BigInt =
I'm totally new to Scala. Here I have tried to assign a empty array
I'm new to the Scala type system, and I'm trying to explore it via
I'm really new to Scala and I'm not even able to concatenate Strings. Here
I am new to scala. I want to be notified whenever a map is
I'm new to Scala, and I want to write some multi-threaded code with pattern

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.