{"id":15289150,"url":"https://github.com/plippe/play-form","last_synced_at":"2025-03-24T06:42:03.087Z","repository":{"id":57722124,"uuid":"257383987","full_name":"plippe/play-form","owner":"plippe","description":"A module to submit forms with commonly unsupported browser methods like `PUT`, `PATCH`, and `DELETE`","archived":false,"fork":false,"pushed_at":"2022-09-29T20:43:34.000Z","size":13,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-29T12:22:34.773Z","etag":null,"topics":["play-framework","scala"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/plippe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"plippe"}},"created_at":"2020-04-20T19:31:47.000Z","updated_at":"2022-09-29T20:43:37.000Z","dependencies_parsed_at":"2022-08-29T23:00:41.506Z","dependency_job_id":null,"html_url":"https://github.com/plippe/play-form","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plippe%2Fplay-form","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plippe%2Fplay-form/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plippe%2Fplay-form/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plippe%2Fplay-form/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/plippe","download_url":"https://codeload.github.com/plippe/play-form/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245223855,"owners_count":20580361,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["play-framework","scala"],"created_at":"2024-09-30T15:59:25.632Z","updated_at":"2025-03-24T06:42:03.064Z","avatar_url":"https://github.com/plippe.png","language":"Scala","funding_links":["https://github.com/sponsors/plippe"],"categories":[],"sub_categories":[],"readme":"# Play Form ![Scala CI](https://github.com/plippe/play-form/workflows/Scala%20CI/badge.svg) ![Maven Central](https://img.shields.io/maven-central/v/com.github.plippe/play-form_2.13)\n\n\u003e The Rails framework encourages RESTful design of your applications, which means you'll be making a lot of \"PATCH\", \"PUT\", and \"DELETE\" requests (besides \"GET\" and \"POST\"). However, most browsers don't support methods other than \"GET\" and \"POST\" when it comes to submitting forms.\n\u003e\n\u003e Rails works around this issue by emulating other methods over POST with a hidden input named \"_method\", which is set to reflect the desired method:\n\u003e\n\u003e ```\n\u003e form_with(url: search_path, method: \"patch\")\n\u003e ```\n\u003e\n\u003e Output:\n\u003e\n\u003e ```\n\u003e \u003cform accept-charset=\"UTF-8\" action=\"/search\" data-remote=\"true\" method=\"post\"\u003e\n\u003e   \u003cinput name=\"_method\" type=\"hidden\" value=\"patch\" /\u003e\n\u003e   \u003cinput name=\"authenticity_token\" type=\"hidden\" value=\"f755bb0ed134b76c432144748a6d4b7a7ddf2b71\" /\u003e\n\u003e    ...\n\u003e \u003c/form\u003e\n\u003e ```\n\u003e\n\u003e When parsing POSTed data, Rails will take into account the special _method parameter and act as if the HTTP method was the one specified inside it (\"PATCH\" in this example).\n\u003e\n\u003e [Ruby on Rails](https://guides.rubyonrails.org/form_helpers.html#how-do-forms-with-patch-put-or-delete-methods-work-questionmark)\n\nPlay doesn't offer this feature, but this module does.\n\n## Getting Started\nTo get started you add `play-form` as a dependency in SBT:\n\n```scala\nlibraryDependencies += \"com.github.plippe\" %% \"play-form\" % \"2.8.x\"\n```\n\nAfter that you need to configure the [request handler](https://www.playframework.com/documentation/2.8.x/ScalaHttpRequestHandlers) inside your application.conf:\n\n```hocon\nplay.http.requestHandler = \"com.github.plippe.play.form.DefaultHttpRequestHandler\"\n```\n\n## Usage\nUse `@com.github.plippe.play.form.form` instead of `@helper.form` like the bellow example from [Play's documentation](https://www.playframework.com/documentation/2.8.x/ScalaForms#Showing-forms-in-a-view-template).\n\n```diff\n-@helper.form(action = routes.Application.userPost()) {\n+@com.github.plippe.play.form.form(action = routes.Application.userPost()) {\n  @helper.inputText(userForm(\"name\"))\n  @helper.inputText(userForm(\"age\"))\n}\n```\n\n## Versioning\nPlay Form supports several different versions of Play.\n\n| Play Form version | Play version |\n|-------------------|--------------|\n| 2.8.x             | 2.8.x        |\n| 2.7.x             | 2.7.x        |\n| 2.6.x             | 2.6.x        |\n\n## Import\nTo remove the need to write the full package name, you can import the form in your `build.sbt`:\n```scala\nTwirlKeys.templateImports += \"com.github.plippe.play.form.form\"\n```\n\nThis would simplify the views.\n```diff\n-@helper.form(action = routes.Application.userPost()) {\n+@form(action = routes.Application.userPost()) {\n  @helper.inputText(userForm(\"name\"))\n  @helper.inputText(userForm(\"age\"))\n}\n```\n\n## Cross Site Request Forgery (CSRF)\n\u003e By default, Play will require a CSRF check when all of the following are true:\n\u003e - The request method is not GET, HEAD or OPTIONS.\n\u003e - The request has one or more Cookie or Authorization headers.\n\u003e - The CORS filter is not configured to trust the request’s origin.\n\u003e\n\u003e [Play's documentation](https://www.playframework.com/documentation/2.8.x/ScalaCsrf)\n\nIf you encounter `Unauthorized` errors, your request most likely fails the CSRF check. [Play's documentation](https://www.playframework.com/documentation/2.8.x/ScalaCsrf) offers a few solutions. I choose the `@helper.CSRF.formField` in the [example project](https://github.com/plippe/play-form/tree/master/example).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplippe%2Fplay-form","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplippe%2Fplay-form","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplippe%2Fplay-form/lists"}