{"id":13417813,"url":"https://github.com/pilcrowOnPaper/astro-form-actions","last_synced_at":"2025-03-15T02:31:41.574Z","repository":{"id":65353431,"uuid":"590433271","full_name":"pilcrowonpaper/astro-form-actions","owner":"pilcrowonpaper","description":"Forms in Astro made easy","archived":true,"fork":false,"pushed_at":"2023-01-26T02:02:23.000Z","size":589,"stargazers_count":24,"open_issues_count":0,"forks_count":15,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-06T21:41:12.461Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://astro-form-actions.vercel.app","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pilcrowonpaper.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2023-01-18T12:07:06.000Z","updated_at":"2024-03-11T23:37:55.000Z","dependencies_parsed_at":"2023-02-14T13:15:19.295Z","dependency_job_id":null,"html_url":"https://github.com/pilcrowonpaper/astro-form-actions","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":"pilcrowOnPaper/ts-package","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pilcrowonpaper%2Fastro-form-actions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pilcrowonpaper%2Fastro-form-actions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pilcrowonpaper%2Fastro-form-actions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pilcrowonpaper%2Fastro-form-actions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pilcrowonpaper","download_url":"https://codeload.github.com/pilcrowonpaper/astro-form-actions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243674976,"owners_count":20329182,"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":[],"created_at":"2024-07-30T22:00:53.262Z","updated_at":"2025-03-15T02:31:41.136Z","avatar_url":"https://github.com/pilcrowonpaper.png","language":"TypeScript","funding_links":[],"categories":["What Do I Use..."],"sub_categories":["If I want to handle form submissions?"],"readme":"# Astro form actions\n\nUse progressive form enhancement and handle form submissions in Astro. This library only uses native Web APIs and can be used in any runtime.\n\n```\nnpm i astro-form-actions\npnpm add astro-form-actions\nyarn add astro-form-actions\n```\n\n**Documentation: https://github.com/pilcrowOnPaper/astro-form-actions/wiki**\n\n**Demo: https://astro-form-actions.vercel.app**\n\n\u003e Need a library to parse your forms? Check out my other project [Adria](https://github.com/pilcrowOnPaper/adria)!\n\n### Features\n\n- Simple\n- Type inference\n- Supports multipart form data\n- Framework agnostic\n\n## Overview\n\nThis library is made up of 2 parts: server side and client side.\n\n### Server side\n\n`handleFormSubmission` will handle all POST requests to the page.\n\n```ts\n// inside .astro page\nimport {\n\thandleFormSubmission,\n\treject,\n\tresolve,\n\tredirect\n} from \"astro-form-actions\";\n\nconst { response, error, inputValues, body } = await handleFormSubmission(\n\tAstro,\n\tasync (formData) =\u003e {\n\t\tconst message = formData.get(\"message\");\n\t\tif (typeof notes !== \"string\")\n\t\t\treturn reject(400, {\n\t\t\t\tmessage: \"bad input\"\n\t\t\t});\n\t\t// do some stuff\n\t\treturn resolve({\n\t\t\tsuccess: true\n\t\t});\n\t}\n);\nif (response) return response;\n```\n\n### Client side\n\nYou can use a regular HTML form:\n\n```html\n\u003cform method=\"post\"\u003e\n\t\u003cinput name=\"message\" /\u003e\n\t\u003cinput type=\"submit\" /\u003e\n\u003c/form\u003e\n```\n\nOr, by using component frameworks like Solid (or just even vanilla JS), you can use `submitForm` to make the submission.\n\n```tsx\nimport { submitForm } from \"astro-form-actions/client\";\n\nexport default () =\u003e {\n\treturn (\n\t\t\u003cform\n\t\t\tmethod=\"post\"\n\t\t\tonSubmit={(e) =\u003e {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst { error } = await submitForm\u003c\n\t\t\t\t\t{\n\t\t\t\t\t\tsuccess: boolean;\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tmessage: string;\n\t\t\t\t\t}\n\t\t\t\t\u003e(e.currentTarget);\n\t\t\t}}\n\t\t\u003e\n\t\t\t\u003cinput name=\"message\" /\u003e\n\t\t\t\u003cinput type=\"submit\" /\u003e\n\t\t\u003c/form\u003e\n\t);\n};\n```\n\n## Other\n\nParts of the library is from https://github.com/nachomazzara/parse-multipart-data.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FpilcrowOnPaper%2Fastro-form-actions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FpilcrowOnPaper%2Fastro-form-actions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FpilcrowOnPaper%2Fastro-form-actions/lists"}