Svelte
Learn how to integrate your Formbox form with Svelte.
What is Svelte?
Svelte is a tool for building web applications. Like other user interface frameworks, it allows you to build your app declaratively out of components that combine markup, styles and behaviours.
Prerequisites
Before you begin, you’ll need to have a Formbox form. If you don’t have one yet, you can create a new form by following the steps in the Introduction guide. Once you have your form, make a note of the form’s endpoint url in the setup tab of your form page, as you’ll need it later.
Creating a new Svelte project
To get up and running quickly, we will follow the official Svelte Getting Started guide to create a new Svelte project. In your terminal, run the following command:
The first command will scaffold a new project in the svelte-with-formbox
directory asking you if you’d like to set up some basic tooling such as TypeScript. Once all questions are answered, it will begin scaffolding your project and provide instructions for navigating to your site and running it locally.
Go to the new directory for the new website:
Start the development server:
Open your browser and navigate to http://localhost:5173
. You should see a new Svelte application running.
Adding your Formbox form to your Svelte project
Now that we have a new Svelte project set up, let’s add our Formbox form to it.
For styling purposes, we’ll use Tailwind CSS. You can learn how to add Tailwind CSS to your project by following the Svelte installation guide.
Once you have Tailwind CSS set up, let’s add our form.
Open up the +page.svelte
file within the src/routes
directory and replace everything in the file with the following code block:
Paste the form endpoint url you copied from Formbox into your form’s action
attribute as shown in the code block above.
Save the file and navigate to http://localhost:5173
in your browser. You should see a form that you can fill out and submit.
And that’s it! Now after filling out and submitting the form you should see the default submission success page displayed.