Forms & Fields

Generate typed SFCC and SFRA forms from XML, complete field values, and navigate back to form definitions

Form XML drives more than runtime validation. The language server reads cartridge form definitions and generates types for the native SFCC form model and SFRA's server.forms.getForm() wrapper. Field names, groups, includes, actions, and value types become part of script intelligence.

Define a small form

cartridge/forms/default/newsletter.xml
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.demandware.com/xml/form/2008-04-19">
    <field formid="email" type="string" mandatory="true" />
    <field formid="subscribe" type="boolean" />
    <action formid="submit" valid-form="true" />
</form>

After the form is indexed, access it through either form API:

var server = require('server');
var form = server.forms.getForm('newsletter');
var email = form.email.value;
var subscribed = form.subscribe.checked;

The literal form name selects the generated SFRA shape. Field wrappers include value, valid, error, HTML names, and type-specific members such as boolean checked and selected.

cartridge/templates/default/newsletter/form.isml
<isscript>
    var form = pdict.CurrentForms.newsletter;
    var email = form.email.value;
    var valid = form.valid;
</isscript>

In a template, pdict.CurrentForms uses the generated SfccForms map. Native field members use dw.web.FormField with the declared value type. The generated form group exposes its named fields and actions. The bundled session.forms declaration is more generic; use an explicit SfccForms annotation if you need that generated shape through session.forms.

Invoke completion after form. to discover fields; hover form.email.value to inspect its type. Use Go to Definition on 'newsletter' in server.forms.getForm() or a generated field member to return to the corresponding XML.

What the generator models

Form structureGenerated support
Named fieldsField members with the declared value type; integer and number fields map to numbers
Nested groupsNested typed form groups
Included formsIncluded structure is resolved into the form model
ActionsNative form actions and SFRA action properties
SFRA string fieldsString-specific members such as minimum length, maximum length, and regular expression
SFRA numeric fieldsMinimum and maximum value members
SFRA boolean fieldsChecked and selected state

Generated declarations are written to .intellij-sfcc/generated/form-types.d.ts. Edit the form XML and let the generator refresh it. Runtime form validation still depends on the deployed XML and submitted request; editor types do not simulate form submission.

On this page