AI prompt

Give this prompt to your AI coding assistant (Claude, Cursor, ChatGPT, Lovable, Bolt...) to connect a form of your website to BackMyForm, or to create one. The assistant asks you what it needs first, then writes the form with the right settings.

How to use it

  1. Create the form in BackMyForm, and copy its short id: the end of its endpoint, https://submit.backmyform.com/f/{shortId}. You can also give the whole endpoint.
  2. Paste the prompt below in your assistant, in your project.
  3. Answer its questions: the short id, the page of the form, the fields, the files, and what happens after the submission.
  4. Check the table of the fields it shows you, then let it write the code.

The prompt

Prompt

Connect a form of this project to BackMyForm, a hosted backend that stores the form submissions. Ask me your questions first, and do not change any code before I have answered them and accepted the fields.

Step 1: ask me
- The short id of my BackMyForm form (8 characters, like k3x9q2mf), or its endpoint. The endpoint is https://submit.backmyform.com/f/{shortId}.
- The form to connect: look for the forms of the project. If there are several, ask me which one. If there is none, ask me on which page to create it, and what it is for (contact, quote request, registration...).
- Whether the form accepts files. If it does: the types of files of each file input, the size limit of a file, and the maximum number of files.
- What happens after the submission: the visitor goes to a thank-you page (a plain HTML form, redirected by BackMyForm), or stays on the page and sees a message (the form is sent with JavaScript).

Step 2: review the fields with me
- Show me a table of the fields the form will have, with the columns: label, name attribute, type, required, status. Status: "kept" for the fields of the existing form, "new" for the fields you add. With no form yet, propose the fields that fit its purpose, all "new".
- The name attribute is the name of the field in BackMyForm: keep the existing names, and use short, readable, stable names for the others (e.g. name="email", name="company"). Two fields never have the same name, except the checkboxes of one question.
- Ask me to validate the fields: I can accept them, remove, add or rename fields, or change a type or the required flag. Wait for my answer, and show the updated table until I accept it.

Step 3: once I have accepted the fields
1. Apply exactly the accepted fields. Keep the design and the texts of an existing form; a new form matches the design of the website (fonts, colors, spacing, buttons).
2. Every input, select and textarea to send must have its accepted name attribute: a field without a name is not sent. The submit button has no name.
3. Set action="https://submit.backmyform.com/f/{shortId}" and method="POST" on the form element, always, even when the form is sent with JavaScript.
4. The form is sent as multipart/form-data or application/x-www-form-urlencoded, never as JSON. With file inputs, add enctype="multipart/form-data" to the form, and set the accept attribute of each file input to its types (e.g. accept=".pdf,.doc,.docx"). With JavaScript, check the size of the files before sending, and show an error next to the file input when a file is too large.
5. With a thank-you page: nothing more, the browser sends the form and BackMyForm redirects the visitor. With a message on the page: on submit, prevent the default behavior and send fetch(form.action, { method: "POST", body: new FormData(form) }), the FormData built from the form at that moment. A 201 response means the submission is saved: show a success message and reset the form. A 413 response with the code "file_too_large" means a file is too large, with "too_many_files" that there are too many files; a 415 response with the code "file_type_not_allowed" means the type of a file is not accepted: show it next to the file input. A 429 response means too many submissions were sent: ask to try again in a minute. Otherwise show an error message. Keep the values on error, and disable the submit button while sending.
6. Add this badge under the submit button, exactly as is, with the short id of the form (it is required on the free plan, and shown only when needed):
   <a href="https://backmyform.com" target="_blank" rel="noopener"><img src="https://submit.backmyform.com/f/{shortId}/badge.svg" alt="Powered by BackMyForm"></a>
7. Add this script once to the page of the form, exactly as is (it records the time to respond and the forms that visitors start without sending them; the form works without it):
   <script src="https://submit.backmyform.com/f/forms.js" defer></script>
   The script adds a hidden field to the form: never add, rename or remove it. Add the data-backmyform-ignore attribute to an element around the fields that must never be saved before the submission (passwords and card numbers are never saved).
8. No API key or secret is needed: never add one to the form.
9. When done, give me the table of the fields as written, and explain how to send a test submission.

What the assistant writes

For a contact form shown on the page after the submission, the result looks like this:

contact.html

<form id="contact" action="https://submit.backmyform.com/f/k3x9q2mf" method="POST">
	<label>Name <input type="text" name="name" required /></label>
	<label>Email <input type="email" name="email" required /></label>
	<label>Message <textarea name="message" required></textarea></label>
	<button type="submit">Send</button>
</form>
<a href="https://backmyform.com" target="_blank" rel="noopener">
	<img src="https://submit.backmyform.com/f/k3x9q2mf/badge.svg" alt="Powered by BackMyForm" />
</a>
<script src="https://submit.backmyform.com/f/forms.js" defer></script>
<script>
	const form = document.querySelector('#contact');

	form.addEventListener('submit', async (event) => {
		event.preventDefault();

		const response = await fetch(form.action, { method: 'POST', body: new FormData(form) });

		if (response.status === 201) {
			form.reset();
			alert('Thank you!');
		} else {
			alert('Something went wrong, please try again.');
		}
	});
</script>

Once the first submission is received, its fields appear in the app, and in the fields of the form of the API.