
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
@statickit/standalone
Advanced tools
The HTML library for StaticKit.
Run the following to install via npm:
npm install @statickit/standalone
If you are not using an npm-based build pipeline, you can install using our CDN instead:
<script defer src="https://js.statickit.com/statickit.js"></script>
It's best to install the script somewhere in your layout file, so it will load on every page. Loading and execution are async, so our script will never impact your site performance.
Here's a simple example of a StaticKit-powered form:
<!-- On the page -->
<form id="my-form">
<label for="email">Email</label>
<input id="email" type="email" name="email" value="" />
<button type="submit">Sign up</button>
</form>
If you are using the npm package:
import sk from '@statickit/standalone';
sk('form', 'init', {
id: '[...]',
element: '#my-form'
});
If you are using the CDN:
<script>
window.sk=window.sk||function(){(sk.q=sk.q||[]).push(arguments)};
sk('form', 'init', {
id: '[...]',
element: '#my-form'
});
</script>
At a minimum, you just need to pass your StaticKit form id
via the config object to get a working form.
The most common thing you’ll want to customize is the behavior after the form is submitted. By default, the <form>
element gets replaced with an unstyled “Thank you!” <div>
element.
Here's an example config that replaces the form with a custom message:
sk('form', 'init', {
id: '[...]',
element: '#my-form',
onSuccess: function(config) {
var h = config.h;
var form = config.form;
var replacement = h('div.success-message', 'Thank you for joining!');
form.parentNode.replaceChild(replacement, form);
}
});
Let's step through what's happening here:
config.h
is a simple helper for creating DOM nodes called HyperScriptconfig.form
is a reference to the <form>
elementreplacement
is new element to swap in for the <form>
If you want to redirect to a different page, you can do that too:
sk('form', 'init', {
id: '[...]',
element: '#my-form',
onSuccess: function(config) {
window.location.href = '/thank-you';
}
});
Most of the time, it will be sufficient to use standard HTML validation attributes, such as the required
attribute. But you can optionally configure server-side validations to ensure bad data does not slip through.
When validation errors occur, the client library will look for an element with a data-sk-error
attribute and populate it with validation errors for the corresponding field:
<form id="my-form">
<label for="email">Email</label>
<input id="email" type="email" name="email" value="" />
<div data-sk-error="email" class="error-message"></div>
<button type="submit">Sign up</button>
</form>
If you need to include some additional fields programmatically, you can define them in the data
config.
// This will append a `userAgent` field to the form data
sk('form', 'init', {
id: '[...]',
element: '#my-form',
data: {
userAgent: navigator.userAgent
}
});
Your data
object values can either be static or functions (that will be called at submission time):
sk('form', 'init', {
id: '[...]',
element: '#my-form',
data: {
pageTitle: function() {
return document.title;
}
}
});
If you have an email notification action configured for your form, you can customize the subject line and reply-to address by including special fields in your form submission:
_subject
- use this field to set the subject line_replyto
or email
- use either of these fields to set the reply addressYou may add <input>
fields to your form to make these settable by the user, or set them programmatically:
sk('form', 'init', {
id: '[...]',
element: '#my-form',
data: {
_subject: 'New contact submission'
}
});
FAQs
The JavaScript client for StaticKit
We found that @statickit/standalone demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.