Skip to content

Your own markup

Every Basin form has an endpoint, https://usebasin.com/f/{id}. Write ordinary HTML with that as its action, and Basin stores whatever fields you send. (To let Basin build the markup instead, see Form Studio forms.)

Look the form up by its Basin ID, then use its action:

{% set form = craft.basin.form('demo0contact') %}
{% if form %}
<form action="{{ form.action }}" method="post">
<label>Email <input type="email" name="email" required></label>
<label>Message <textarea name="message"></textarea></label>
<button type="submit">Send</button>
</form>
{% endif %}

The ID is the last part of the form’s endpoint URL in Basin, and it’s on the form’s page under Basin → Forms, which also has this snippet ready to copy.

Always wrap the form in {% if form %}. craft.basin.form() returns null when the form isn’t in your linked Basin project, for example if it was deleted. Your page then leaves the form out instead of showing visitors a form that can’t be submitted, and the Control Panel warns you.

The form posts to Basin, not to Craft, so don’t add {{ csrfInput() }}. Craft’s CSRF protection doesn’t apply.

You don’t need to add anything. If Basin requires a CAPTCHA or a honeypot for the form, the plugin adds it to the page automatically. To control where they go, see Spam protection.

To send files, add enctype="multipart/form-data" to the <form> tag. Uploaded files appear as attachments on the submission in the Control Panel.

By default, Basin shows its own thank-you page. To change its message, or send visitors back to your site instead, use Redirects in the form’s Settings → General in Basin.

To submit without leaving the page, post the form with fetch() and ask for JSON:

{% set form = craft.basin.form('demo0contact') %}
{% if form %}
<form action="{{ form.action }}" method="post" id="contact">
<input type="email" name="email" required>
<textarea name="message"></textarea>
<button type="submit">Send</button>
</form>
<script>
document.getElementById('contact').addEventListener('submit', async (event) => {
event.preventDefault();
const form = event.target;
const response = await fetch(form.action, {
method: 'POST',
body: new FormData(form),
headers: { Accept: 'application/json' },
});
form.replaceWith(response.ok ? 'Thanks, we’ll be in touch.' : 'Sorry, something went wrong.');
});
</script>
{% endif %}

Basin responds with JSON whenever a request asks for it with Accept: application/json: {"success":true,…} when a submission is accepted, or an error with a 4xx status, such as 422 with {"error":"reCaptcha response must be present"} when a required CAPTCHA is missing.

The automatic spam protection works with this too. For reCAPTCHA v3, it gets a token before your handler runs, so the token is included in FormData.

craft.basin.forms() returns every form in the linked project, sorted by name:

{% for form in craft.basin.forms() %}
{{ form.name }}: {{ form.action }}
{% endfor %}