slapform
v3.0.2
Published
Easily send submission to Slapform, your favorite form backend service.
Maintainers
Readme
Quick start
1. Create a form
Go to slapform.com/dashboard/forms/new to create your form. Copy the Form ID when you're done.
2. Add to your site
Script tag (no build tools needed):
<script src="https://cdn.jsdelivr.net/npm/slapform@latest/dist/slapform.min.js"></script>
<script>
var slapform = new Slapform();
slapform.submit('YOUR_FORM_ID', {
name: 'Jon Snow',
message: 'Hello World!',
})
.then(function (response) {
console.log('Success!', response);
})
.catch(function (error) {
console.error('Failed:', error.message);
});
</script>NPM:
npm install slapform// ESM
import Slapform from 'slapform';
// CommonJS
const Slapform = require('slapform');const slapform = new Slapform({ formId: 'YOUR_FORM_ID' });
const response = await slapform.submit({
name: 'Jon Snow',
message: 'Hello World!',
});HTML form (no JavaScript needed)
You can use Slapform without any JavaScript by pointing your HTML form's action to the API:
<form method="POST" action="https://api.slapform.com/YOUR_FORM_ID">
<input type="email" name="email">
<textarea name="message"></textarea>
<button type="submit">Submit</button>
</form>API
new Slapform(options)
| Option | Default | Description |
|--------|---------|-------------|
| formId | '' | Your form ID (also accepts form) |
| endpoint | 'https://api.slapform.com' | API endpoint |
slapform.submit(formId?, data, options?)
Submits form data. Returns a promise that resolves with the API response.
- formId (optional) — Form ID string. Overrides the constructor's
formId - data — Object with the fields you want to submit
- options — Optional overrides for
formIdandendpoint
// Pass formId inline
slapform.submit('YOUR_FORM_ID', { message: 'Hello' });
// Or use the constructor default and just pass data
const sf = new Slapform({ formId: 'YOUR_FORM_ID' });
sf.submit({ message: 'Hello' });
// Override formId via options
sf.submit({ message: 'Hello' }, { formId: 'DIFFERENT_FORM_ID' });Name triggers
Use special field names to trigger server-side behavior:
slapform.submit('YOUR_FORM_ID', {
name: 'Jon Snow',
message: 'Hello World!',
slap_subject: 'My Favorite Message',
slap_replyto: '[email protected]',
slap_debug: false,
slap_honey: '',
});See the name trigger documentation for details.
Features
- Submit data via HTML forms, AJAX, or this npm module
- Submissions are sent directly to your email
- Access submissions stored securely for up to 12 months
- Spam protection
- Zapier integration
Development
npm start # Watch mode - rebuilds on file changes
npm run build # One-time build (ESM, CJS, IIFE)
npm test # Run testsBuild outputs
| File | Format | Use case |
|------|--------|----------|
| dist/index.mjs | ESM | import in modern bundlers |
| dist/index.js | CJS | require() in Node.js |
| dist/slapform.min.js | IIFE (minified) | <script> tag / CDN |
License
MIT
