$wsForm module, you can use form data dynamically in the frontend, load form fields, and read out submitted form data.
Module overview
Example / excerpt of$wsForm
ƒ() denotes a function.
Variables overview
| Name | Return type | Description |
|---|---|---|
inquiryId | string | Contains the ID after sending a form. |
loadType() | map | Loads the structure of a form by the form name. |
loadAllTypes() | array | Loads all available form types of the shop. |
load() | map | Loads the submitted data of a sent form. |
Templates
Forms are used everywhere in the shop and on all templates. These forms are, for example:- Contact form
- Withdrawal form
- Question about the product
- Password reset
Variables
$wsForm.inquiryId
Contains the unique ID of a form inquiry after successful sending. With this ID, the form data can be retrieved viaload().
Methods
$wsForm.loadType()
Loads the structure of a form (fields, labels, validations) by the form ID. Signature$wsForm.loadType(inquiryId)
Return valuemap - Map with the form properties and fields.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
inquiryId | string | yes | ID of the form (e.g. “contact”). |
Variables of the field objects
The
$wsForm.loadtype() method returns an object per field (in this example $myField) with the following properties. If a RuleSet (inquiry - Forms) is assigned to the form, the attributes required and label are automatically adjusted by the rules defined there.| Variable | Return type | Description |
|---|---|---|
$myField.name | string | Technical field name. |
$myField.label | string | Display name of the field. Is automatically updated by customLabelDefinition in the RuleSet if a RuleSet is linked. |
$myField.required | bool | Required-field flag (true / false). Is automatically updated by requiredDefinition in the RuleSet. |
$myField.validations | array | List of validation rules for the field. |
$myField.defaultValue | string | Default value of the field (set by defaultValuesDefinition in the RuleSet). Can be used in the template to pre-populate the field value when it is empty. |
$myField.value | string | Current value of the field. Is populated by the inquiryCheck action (see actions - Forms). |
$myField.visible | bool | Indicates whether the field should be displayed (true / false). Is automatically controlled by inputVisibilityDefinition in the RuleSet. |
$wsForm.loadAllTypes()
Loads all available form types of the shop Signature$wsForm.loadAllTypes()
Return valuearray - List of all available form types.
Example that iterates over all available form types.
$wsForm.load()
Loads the submitted data of a sent form. Signature$wsForm.load(inquiryId)
Return valuemap - Map with the inquiry data.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
inquiryId | string | yes | ID of the sent form. |
- Create action “
InquirySend” - Check whether sending was successful
- Load form data via the
Inquiry ID
load():
| Variable | Return type | Description |
|---|---|---|
id | string | Unique ID of the form inquiry. |
formId | string | ID of the form used. |
createdAt | string | Time of sending. |
submitter | map | Data of the sender. |
email | string | Email address of the sender. |
sessionId | string | Session ID during which the form was sent. |
ipAddress | string | IP address of the sender. |
form | map | Data of the form that the customer entered in the shop. |
"fieldName".label | string | Display name of the field. |
"fieldName".value | string | Entered value of the field. |
Variables of the inquiry data
$myInquiry.id
Returns the unique ID of the form inquiry.$myInquiry.formId
Returns the ID of the form used.$myInquiry.createdAt
Returns the time of sending.$myInquiry.submitter
Returns a map with data about the sender.$myInquiry.submitter.email
Returns the email address of the sender.$myInquiry.submitter.sessionId
Returns the session ID during which the form was sent.$myInquiry.submitter.ipAddress
Returns the IP address of the sender.$myInquiry.form
Returns the data of the form inquiry that the customer entered in the shop as a map.$myInquiry.form.”fieldName”.label
Returns the display name of the field.$myInquiry.form.”fieldName”.value
Returns the entered value of the field.Actions
Actions for this module that trigger changes are documented separately in the “Actions” chapter: InquiryExample for displaying form fields
Function - loadType
The function$wsForm.loadType() takes the name of the form as an argument and is used to access the properties and fields of the form.
The fields and associated properties of the contact form can then be loaded and read as follows.
Function - load
The function$wsForm.load() is used to access the submitted data of a sent form. This can be used, for example, to show the user the submitted information in the frontend or via email.
This example checks whether the form was successfully sent and loads the inquiry data. This is done as follows (commented out so that the output is not displayed directly in the frontend):
Example: display data in the frontend
This example loads and displays the data of a sent form using the$wsForm.load() function.
→ Practical examples: forms
