Skip to main content

<st-contact-form>

JSON type: ContactForm

A contact form for a website: name, work e-mail, company, an optional phone, a topic, a message and a required consent box. It posts the answers as JSON to endpoint and shows what came back: a success note (with the reference, when the API gives one), field messages from the server, or a short note when the message could not be sent. The text the server sends is never shown. Only the component's own labels and messages, plus the server's per-field messages, appear on the page.

Every rule is checked in the browser first, the same rules the server applies, so a visitor sees the problem before anything is sent. The server still decides, and a field it rejects is shown with its message while the visitor's input is kept. A hidden honeypot field (website) must stay empty.

topics lists the choices, grouped by each item's group. The topic is preselected from the page URL: ?product= wins, then ?topic=, each when it names one of the topics. default-topic is the fallback. An "About:" pill shows when the URL chose the topic.

The form does not clear the message on an error, and the button is disabled while a request is in flight. Removing the element aborts a request that has not finished.

When three or more fields fail, a summary (role="alert") at the top of the form lists each error as a link to its field, and focus moves to the summary. With one or two failing fields, focus goes to the first one.

The notes for a network failure or a rate limit may contain {mailto}; it becomes a mailto: link to the mailto address. A message the server sends is shown as plain text and is never given a link.

The message counter appears from 80% of the limit. Screen readers are told when it passes 80%, 90% and the limit.

None of the events carries personal data (no name, e-mail, company, phone or message text).

Usage​

import '@sankhyatronics/sankhya-cms/contact-form'; // registers <st-contact-form>

Properties​

PropertyAttributeTypeDefaultDescription
endpointendpointstring''Absolute http(s) URL of the contact API. Empty: the form still renders, and submitting shows the error note without sending.
topicstopicsContactTopic[][]The choices for the topic select. Also set as the JSON attribute topics. Items with a group are put under that &lt;optgroup&gt;.
defaultTopicdefault-topicstring''The topic to preselect when the page URL does not choose one. Ignored unless it is one of topics.
showPhoneshow-phonebooleantrueShows the optional phone field. Set show-phone="false" to hide it.
localelocalestring''Language sent with the message. Empty uses the page's lang, or en.
pagepagestring''Page sent with the message. Empty uses the page's path.
nameLabelname-labelstring'Full name'
emailLabelemail-labelstring'Work email'
companyLabelcompany-labelstring'Company'
phoneLabelphone-labelstring'Phone (optional)'
topicLabeltopic-labelstring'Topic'
topicPlaceholdertopic-placeholderstring'Select a topic'
messageLabelmessage-labelstring'Message'
namePlaceholdername-placeholderstring'Your name'
emailPlaceholderemail-placeholderstring'you@company.com'
companyPlaceholdercompany-placeholderstring'Your company'
messagePlaceholdermessage-placeholderstring'Tell us what you need'
messageCountermessage-counterstring'{count} / {max}'The message counter. &#123;count&#125; and &#123;max&#125; are filled in.
submitLabelsubmit-labelstring'Send message'
sendingLabelsending-labelstring'Sending…'
requiredLabelrequired-labelstring'required'Shown in brackets after each required label, for screen readers.
aboutLabelabout-labelstring'About:'The text before the topic in the "About:" pill.
consentLabelconsent-labelstring'I agree that Sankhyatronics may use these details to reply to my enquiry.'
privacyNoteprivacy-notestring''A line of privacy text above the submit button. Empty hides it.
privacyLinkLabelprivacy-link-labelstring'Privacy Policy'
privacyHrefprivacy-hrefstring'/privacy-policy'
sentNotesent-notestring'Thanks, your message has been sent. We will reply soon.'
referenceLabelreference-labelstring'Your reference:'
errorNoteerror-notestring'Sorry, your message could not be sent. Please try again later.'
rateLimitedNoterate-limited-notestring'You have sent several messages in a short time. Please wait {seconds} seconds and try again.'Rate-limit note. &#123;seconds&#125; is filled in when the server says how long to wait.
rateLimitedGenericNoterate-limited-generic-notestring'You have sent several messages in a short time. Please wait a little and try again.'
errorSummaryerror-summarystring'Please fix {count} fields.'The field-error summary for screen readers, when several fields fail. &#123;count&#125; is filled in.
errorSummaryOneerror-summary-onestring'Please fix {count} field.'The summary when one field fails.
requiredNoterequired-notestring'* Required'The note above the fields. The form's aria-describedby points at it. Empty hides it.
mailtomailtostring''Address for &#123;mailto&#125; in the error and rate-limit notes. Empty, or not an address, leaves the placeholder out.
errorMessages—Partial<ContactErrorMessages>{}Replaces the English validation messages (required, tooLong, ...). Only the keys given are replaced.

Events​

EventDetailDescription
CONTACT_FORM_SUBMIT_EVENTCustomEvent
CONTACT_FORM_SENT_EVENTCustomEvent
CONTACT_FORM_ERROR_EVENTCustomEvent
st-contact-form-submitBubbles and is composed. Detail &#123; topic: string &#125; (the chosen topic's value). The checks passed and the request is about to be sent.
st-contact-form-sentBubbles and is composed. Detail &#123; reference?: string &#125;. The form has been cleared.
st-contact-form-errorBubbles and is composed. Detail &#123; kind: 'validation' | 'rate_limited' | 'unavailable' &#125;. The input is kept.

See the live examples in Storybook.