play.api.data

Form

case class Form [T] (mapping: Mapping[T], data: Map[String, String], errors: Seq[FormError], value: Option[T]) extends Product with Serializable

Helper to manage HTML form description, submission and validation.

For example, a form handling a User case class submission:

import play.api.data._
import play.api.data.format.Formats._

val userForm = Form(
  mapping(
    "name" -> of[String],
    "age" -> of[Int],
    "email" -> of[String]
  )(User.apply)(User.unapply)
)
T

the type managed by this form

mapping

the form mapping, which describes all form fields

data

the current form data, used to display the form

errors

the collection of errors associated with this form

value

a concrete value of type T if the form submission was successful

Linear Supertypes
Serializable, Serializable, Product, Equals, AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Hide All
  2. Show all
  1. Form
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. AnyRef
  7. Any
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Form (mapping: Mapping[T], data: Map[String, String], errors: Seq[FormError], value: Option[T])

    mapping

    the form mapping, which describes all form fields

    data

    the current form data, used to display the form

    errors

    the collection of errors associated with this form

    value

    a concrete value of type T if the form submission was successful

Value Members

  1. def != (arg0: AnyRef): Boolean

    Attributes
    final
    Definition Classes
    AnyRef
  2. def != (arg0: Any): Boolean

    Attributes
    final
    Definition Classes
    Any
  3. def ## (): Int

    Attributes
    final
    Definition Classes
    AnyRef → Any
  4. def == (arg0: AnyRef): Boolean

    Attributes
    final
    Definition Classes
    AnyRef
  5. def == (arg0: Any): Boolean

    Attributes
    final
    Definition Classes
    Any
  6. def apply (key: String): Field

    Retrieves a field.

    Retrieves a field.

    For example:

    val usernameField = userForm("username")
    
    key

    the field name

    returns

    the field, returned even if the field does not exist

  7. def asInstanceOf [T0] : T0

    Attributes
    final
    Definition Classes
    Any
  8. def bind (data: JsValue): Form[T]

    Binds data to this form, i.

    Binds data to this form, i.e. handles form submission.

    data

    Json data to submit

    returns

    a copy of this form, filled with the new data

  9. def bind (data: Map[String, String]): Form[T]

    Binds data to this form, i.

    Binds data to this form, i.e. handles form submission.

    data

    the data to submit

    returns

    a copy of this form, filled with the new data

  10. def bindFromRequest ()(implicit request: play.api.mvc.Request[_]): Form[T]

    Binds request data to this form, i.

    Binds request data to this form, i.e. handles form submission.

    returns

    a copy of this form filled with the new data

  11. def canEqual (arg0: Any): Boolean

    Definition Classes
    Form → Equals
  12. def clone (): AnyRef

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  13. val constraints : Map[String, Seq[(String, Seq[Any])]]

    Constraints associated with this form, indexed by field name.

  14. val data : Map[String, String]

    the current form data, used to display the form

  15. def eq (arg0: AnyRef): Boolean

    Attributes
    final
    Definition Classes
    AnyRef
  16. def equals (arg0: Any): Boolean

    Definition Classes
    Form → Equals → AnyRef → Any
  17. def error (key: String): Option[FormError]

    Retrieve the first error for this key.

    Retrieve the first error for this key.

    key

    field name.

  18. def errors (key: String): Seq[FormError]

    Retrieve all errors for this key.

    Retrieve all errors for this key.

    key

    field name.

  19. val errors : Seq[FormError]

    the collection of errors associated with this form

  20. def errorsAsJson (implicit lang: Lang): JsValue

    Returns the form errors serialized as Json.

  21. def fill (value: T): Form[T]

    Fills this form with a existing value, used for edit forms.

    Fills this form with a existing value, used for edit forms.

    value

    an existing value of type T, used to fill this form

    returns

    a copy of this form filled with the new data

  22. def fillAndValidate (value: T): Form[T]

    Fills this form with a existing value, and performs a validation.

    Fills this form with a existing value, and performs a validation.

    value

    an existing value of type T, used to fill this form

    returns

    a copy of this form filled with the new data

  23. def finalize (): Unit

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  24. def fold [R] (hasErrors: (Form[T]) ⇒ R, success: (T) ⇒ R): R

    Handles form results.

    Handles form results. Either the form has errors, or the submission was a success and a concrete value is available.

    For example:

      anyForm.bindFromRequest().fold(
         f => redisplayForm(f),
         t => handleValidFormSubmission(t)
      )
    
    R

    common result type

    hasErrors

    a function to handle forms with errors

    success

    a function to handle form submission success

    returns

    a result R.

  25. def forField [R] (key: String)(handler: (Field) ⇒ R): R

    Applies a function for a field.

    Applies a function for a field.

    For example:

    userForm.forField("username") { field =>
      <input type="text" name={field.name} value={field.value.getOrElse("")} />
    }
    
    R

    result type

    key

    field name

    handler

    field handler (transform the field to R)

  26. val formats : Map[String, (String, Seq[Any])]

    Formats associated to this form, indexed by field name.

    Formats associated to this form, indexed by field name. *

  27. def get : T

    Returns the concrete value, if the submission was a success.

    Returns the concrete value, if the submission was a success.

    Note that this method fails with an Exception if this form as errors.

  28. def getClass (): java.lang.Class[_]

    Attributes
    final
    Definition Classes
    AnyRef → Any
  29. def globalError : Option[FormError]

    Retrieves the first global error, if it exists, i.

    Retrieves the first global error, if it exists, i.e. an error without any key.

    returns

    an error

  30. def globalErrors : Seq[FormError]

    Retrieves all global errors, i.

    Retrieves all global errors, i.e. errors without a key.

    returns

    all global errors

  31. def hasErrors : Boolean

    Returns true if there is an error related to this form.

  32. def hasGlobalErrors : Boolean

    Returns true if there is a global error related to this form.

  33. def hashCode (): Int

    Definition Classes
    Form → AnyRef → Any
  34. def isInstanceOf [T0] : Boolean

    Attributes
    final
    Definition Classes
    Any
  35. val mapping : Mapping[T]

    the form mapping, which describes all form fields

  36. def ne (arg0: AnyRef): Boolean

    Attributes
    final
    Definition Classes
    AnyRef
  37. def notify (): Unit

    Attributes
    final
    Definition Classes
    AnyRef
  38. def notifyAll (): Unit

    Attributes
    final
    Definition Classes
    AnyRef
  39. def productArity : Int

    Definition Classes
    Form → Product
  40. def productElement (arg0: Int): Any

    Definition Classes
    Form → Product
  41. def productIterator : Iterator[Any]

    Definition Classes
    Product
  42. def productPrefix : String

    Definition Classes
    Form → Product
  43. def synchronized [T0] (arg0: ⇒ T0): T0

    Attributes
    final
    Definition Classes
    AnyRef
  44. def toString (): String

    Definition Classes
    Form → AnyRef → Any
  45. val value : Option[T]

    a concrete value of type T if the form submission was successful

  46. def wait (): Unit

    Attributes
    final
    Definition Classes
    AnyRef
    Annotations
    @throws()
  47. def wait (arg0: Long, arg1: Int): Unit

    Attributes
    final
    Definition Classes
    AnyRef
    Annotations
    @throws()
  48. def wait (arg0: Long): Unit

    Attributes
    final
    Definition Classes
    AnyRef
    Annotations
    @throws()

Deprecated Value Members

  1. def productElements : Iterator[Any]

    Definition Classes
    Product
    Annotations
    @deprecated
    Deprecated

    use productIterator instead

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from AnyRef

Inherited from Any