{"id":25274915,"url":"https://github.com/francomartino/easy-form-submit","last_synced_at":"2025-04-06T09:17:38.233Z","repository":{"id":275683085,"uuid":"926857618","full_name":"FrancoMartino/easy-form-submit","owner":"FrancoMartino","description":"A JavaScript function designed to simplify form validation and submission handling","archived":false,"fork":false,"pushed_at":"2025-02-04T01:18:43.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-12T14:48:42.506Z","etag":null,"topics":["form","form-validation","formsubmit","formsubmit-co","simple-form","simple-form-validation"],"latest_commit_sha":null,"homepage":"https://cdn.jsdelivr.net/gh/FrancoMartino/easy-form-submit@main/easy-form-submit.min.js","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FrancoMartino.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-04T01:15:35.000Z","updated_at":"2025-02-04T01:20:59.000Z","dependencies_parsed_at":"2025-02-04T02:23:24.030Z","dependency_job_id":"095595c2-e483-49f8-b83d-cfceab0e62af","html_url":"https://github.com/FrancoMartino/easy-form-submit","commit_stats":null,"previous_names":["francomartino/easy-form-submit"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FrancoMartino%2Feasy-form-submit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FrancoMartino%2Feasy-form-submit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FrancoMartino%2Feasy-form-submit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FrancoMartino%2Feasy-form-submit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FrancoMartino","download_url":"https://codeload.github.com/FrancoMartino/easy-form-submit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247457790,"owners_count":20941907,"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":["form","form-validation","formsubmit","formsubmit-co","simple-form","simple-form-validation"],"created_at":"2025-02-12T14:36:00.561Z","updated_at":"2025-04-06T09:17:38.216Z","avatar_url":"https://github.com/FrancoMartino.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# easyFormSubmit\n\n`easyFormSubmit` is a JavaScript function designed to simplify form validation and submission handling in HTML forms. It supports custom validation, additional data submission, and advanced features when used with services like [FormSubmit.co](https://formsubmit.co/). This function is highly customizable and integrates seamlessly with modern web applications.\n\n---\n\n## Installation\n\nNo special installation is required. Simply include the `easyFormSubmit` function from CDN.\n\n```javascript\n\u003cscript src=\"https://cdn.jsdelivr.net/gh/FrancoMartino/easy-form-submit@main/easy-form-submit.min.js\"\u003e\u003c/script\u003e\n```\n\n---\n\n## Usage\n\n### Syntax\n\n```javascript\neasyFormSubmit(formID, options);\n```\n\n### Parameters\n\n- **`formID`** (String): The ID of the form you want to handle.\n- **`options`** (Object): A configuration object with the following optional properties:\n  - **`key`** (String): Your FormSubmit.co email address or key.\n  - **`submitURL`** (String): A custom URL for form submission. Defaults to `https://formsubmit.co/ajax/{key}`.\n  - **`data`** (Object): Additional data to send with the form. This can include advanced FormSubmit.co parameters like `_cc`, `_subject`, `_next`, etc.\n  - **`validate`** (Function): A custom validation function that returns a boolean.\n  - **`onSuccess`** (Function): A callback function executed on successful form submission.\n  - **`onError`** (Function): A callback function executed if an error occurs during submission.\n\n---\n\n## Examples\n\n### Basic Example\n\nThis example submits a form to FormSubmit.co with a custom success message.\n\n```javascript\neasyFormSubmit(\"myForm\", {\n  key: \"your@email.com\", // Your FormSubmit.co email\n  onSuccess: (response) =\u003e {\n    alert(\"Form submitted successfully!\");\n  },\n  onError: (error) =\u003e {\n    alert(\"An error occurred while submitting the form.\");\n  },\n});\n```\n\n---\n\n### Example with Advanced FormSubmit.co Features\n\nThis example uses advanced FormSubmit.co features like `_cc`, `_subject`, `_next`, and `_template`.\n\n```javascript\neasyFormSubmit(\"myForm\", {\n  key: \"your@email.com\", // Your FormSubmit.co email\n  data: {\n    _cc: \"another@email.com,yetanother@email.com\", // CC additional emails\n    _subject: \"New Form Submission\", // Custom email subject\n    _next: \"https://yourdomain.com/thank-you.html\", // Redirect after submission\n    _template: \"table\", // Use the \"table\" email template\n  },\n  onSuccess: (response) =\u003e {\n    console.log(\"Form submitted successfully:\", response);\n  },\n  onError: (error) =\u003e {\n    console.error(\"Error submitting form:\", error);\n  },\n});\n```\n\n---\n\n### Example with Custom Validation\n\nThis example adds custom validation to ensure the email field is valid.\n\n```javascript\neasyFormSubmit(\"myForm\", {\n  key: \"your@email.com\", // Your FormSubmit.co email\n  validate: (form) =\u003e {\n    const email = form.querySelector(\"input[name='email']\").value;\n    return email.includes(\"@\") \u0026\u0026 email.includes(\".\"); // Validate email format\n  },\n  onSuccess: (response) =\u003e {\n    alert(\"Form submitted successfully!\");\n  },\n  onError: (error) =\u003e {\n    alert(\"Form submission failed.\");\n  },\n});\n```\n\n---\n\n### Example with Webhook and Autoresponse\n\nThis example uses a webhook to receive form data in real-time and sends an autoresponse to the user.\n\n```javascript\neasyFormSubmit(\"myForm\", {\n  key: \"your@email.com\", // Your FormSubmit.co email\n  data: {\n    _webhook: \"https://yourdomain.com/webhook\", // Webhook URL\n    _autoresponse: \"Thank you for contacting us! We will get back to you soon.\", // Autoresponse message\n  },\n  onSuccess: (response) =\u003e {\n    console.log(\"Form submitted successfully:\", response);\n  },\n  onError: (error) =\u003e {\n    console.error(\"Error submitting form:\", error);\n  },\n});\n```\n\n---\n\n### Example with Blacklist and Disabled CAPTCHA\n\nThis example filters out spam submissions and disables the CAPTCHA.\n\n```javascript\neasyFormSubmit(\"myForm\", {\n  key: \"your@email.com\", // Your FormSubmit.co email\n  data: {\n    _blacklist: \"spam, badword, phishing\", // Filter out spammy content\n    _captcha: \"false\", // Disable CAPTCHA\n  },\n  onSuccess: (response) =\u003e {\n    console.log(\"Form submitted successfully:\", response);\n  },\n  onError: (error) =\u003e {\n    console.error(\"Error submitting form:\", error);\n  },\n});\n```\n\n---\n\n## Advanced Features\n\n### Supported FormSubmit.co Parameters\n\nYou can include the following advanced parameters in the `options.data` object:\n\n| Parameter        | Description                                                                 |\n|------------------|-----------------------------------------------------------------------------|\n| `_replyto`       | Sets the Reply-To email address.                                            |\n| `_next`          | Redirects the user to a custom URL after submission.                        |\n| `_subject`       | Sets a custom subject for the email.                                        |\n| `_cc`            | Sends a copy of the submission to additional email addresses.               |\n| `_bcc`           | Sends a blind copy of the submission to additional email addresses.         |\n| `_template`      | Sets the email template (`basic`, `table`, or `box`).                       |\n| `_autoresponse`  | Sends an autoresponse email to the user.                                    |\n| `_blacklist`     | Filters out submissions containing specific phrases.                        |\n| `_captcha`       | Enables or disables CAPTCHA (`true` or `false`).                            |\n| `_webhook`       | Sends form data to a webhook URL in real-time.                              |\n\n---\n\n## Function Details\n\n### Custom Validation\n\nYou can provide a custom validation function in the `validate` option. This function receives the form element as a parameter and must return `true` if the validation passes or `false` if it fails.\n\n```javascript\nvalidate: (form) =\u003e {\n  const email = form.querySelector(\"input[name='email']\").value;\n  return email.includes(\"@\") \u0026\u0026 email.includes(\".\");\n}\n```\n\n### Event Handling\n\n- **`onSuccess`**: Executed when the form is submitted successfully. Receives the server response as a parameter.\n- **`onError`**: Executed if an error occurs during submission. Receives the error as a parameter.\n\n### Additional Data\n\nYou can include additional data in the `options.data` object. This data will be sent along with the form data.\n\n```javascript\ndata: {\n  userId: 123,\n  timestamp: new Date().toISOString(),\n}\n```\n\n---\n\n## Notes\n\n- Ensure the form has a unique ID.\n- If no `submitURL` is provided, the function defaults to `https://formsubmit.co/ajax/{key}`.\n- The function uses `fetch` for submissions, so it is compatible with modern browsers.\n\n---\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n---\n\nWe hope `easyFormSubmit` makes form handling easier and more efficient for your projects! If you have any questions or suggestions, please open an issue in the repository.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrancomartino%2Feasy-form-submit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffrancomartino%2Feasy-form-submit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrancomartino%2Feasy-form-submit/lists"}