Salla Docs
Merchant API
  • Merchant API
  • Salla OAuth 2.0
Partner APIs
  • App API
  • Shipment API
Storefront
  • Twilight Engine
  • Twilight SDK
  • Web Components
  • Change Log
Salla CLI
Merchant API
  • Merchant API
  • Salla OAuth 2.0
Partner APIs
  • App API
  • Shipment API
Storefront
  • Twilight Engine
  • Twilight SDK
  • Web Components
  • Change Log
Salla CLI
Salla - Opensource
Salla - Developers Community
  1. Twilight SDK
  • Overview
  • Languages
  • Notify
  • Event
  • Storage
  • Configuration
  • Forms
  • Helpers
  • Auth
    • Login
    • Logout
    • Verify
    • Resend
    • Register
    • Refresh
  • Cart
    • Latest
    • Details
    • Quick Add
    • Add Item
    • Delete Item
    • Delete Image
    • Add Coupon
    • Remove Coupon
    • Get Upload Image
    • Get Quick Order Settings
    • Create Quick Order
    • Order Status
    • Get Current Cart Id
    • Price Quote
  • Wishlist
    • Add
    • Remove
    • Toggle
  • Loyalty
    • Get Program
    • Exchange
    • Reset
  • Comment
    • Add Comment
    • Fetch
    • Get Page Comments
    • Get Product Comments
  • Profile
    • Update profile
    • Update contact
  • Product
    • Get price
    • Product availability
    • Categories
    • Offer details
    • Search products
    • Get Gift Details
    • Add Gift To Cart
    • Upload Gift Image
    • Get Product Details
    • Fetch
    • Fetch Options
    • Size Guides
  • Order
    • Create cart from order
    • Cancel
    • Send invoice
    • Show order
  • Booking
    • Add
  • Rating
    • Order
    • Store
    • Products
    • Shipping
  • Currency
    • Change
    • List
  • Component
    • Reviews
    • Menus
  1. Twilight SDK

Forms

Theme's Forms are typically used to enclose one or more user inputs in order to enable an implicit submit function, in which users can submit an HTML <form> by clicking a "submit" button. This is a generally anticipated behavior that should be addressed as frequently as feasible.
INFO
✅ Twilight JS SDK makes it easier to interact with a Theme's Forms by using the included REST API endpoints. This is to ease tasks connected to API calls, such as Cart APIs, Product APIs, and many others.
In this article, we'll look at how a developer may easily add forms to their Themes. Additionally, how the Form input will be collected upon any change or summit.

📙 What you'll learn#

Twilight Forms
Usage
JS Web Components <salla-button>
Response Schema
Show Message

Twilight Forms#

In Twilight Themes, a form's fields are not automatically submitted via HTTP, unlike the HTML form element. Instead, the developer must include a JavaScript onSubmit callback that will send the required HTTP requests. The following is a complete example for adding a form to collect a comment on a product:

Usage#

In the previous example, developers may notice that the HTML <form> element contains the onsubmit attribute, which is an event. This event is triggered when the form is submitted. Sequentially, the method salla.comment.add will be implemented, which is one of the Twilight API JS SDK methods. 
Under the hood, the event onSubmit calls the helper method salla.comment.add, which in its turn converts all of the form inputs to an object and passes it as arguments to that method. Below is that code that will be run as a result of submitting the previous form:

JS Web Components <salla-button>#

As what will see in the next section of this documentation, Twiligh is shipped with a ready-designed and styled set of JS Web Components. These components are a collection of high-level building blocks and reusable web components that can be built together to swiftly develop the UI for custom Salla Themes. One of the main JS Web Components is the <salla-button> which allows calling functions built by Salla to carry out certain activities.
In the previous example, the <salla-button> is used to submit the form, which causes the helper method salla.comment.add to be called and implemented. It will be loaded automatically and wait for any response from the server.

Response Schema#

The previous <salla-button> component will receive the server Response, which looks like the following schema:

Show Message#

The developer can show an alert message to the end user by adding a message to the response and a success flag indicating whether or not the message was successful.
Success
Error
Modified at 2025-03-04 12:54:02
Previous
Configuration
Next
Helpers