Cert++
Close

Persisting form input to system object attributes or custom objects

Key Takeaway

A submitted form lives in an in-memory form object that lasts only for the session. To keep the data, add a custom attribute to a system object such as Profile, then write the value through that object's custom attributes inside Transaction.wrap.

Data a storefront customer submits through a form first lives in an in-memory form object that lasts only for the session. To keep the data, a controller copies the validated values onto a persistent business object. That object is either a system object with a custom attribute, such as a customer profile or address, or a custom object type you define. Both kinds of storage use the B2C Commerce metadata system, so you declare the attribute or type in Business Manager first and then write to it from code.

The in-memory form object

Use a B2C Commerce form definition for a form that stores data, needs server-side validation, or has sophisticated localization. A plain HTML form suits simple forms that don't store data.

A field in the form definition can carry a binding attribute, for example binding="firstName" on a firstname field. Business Manager metadata for a system or custom object can also feed form definition information. Attributes such as field labels are then managed in one place, so merchants can change them without code changes.

In SFRA, server.forms.getForm('profile') builds a JSON form object from the form definition. This in-memory form object keeps its data for the whole session unless you call clear(). The form object isn't permanent storage, so saving the data means writing its values to a business object.

B2C Commerce Developer Study Guide

Checklist progress

0/237Learned

Given a requirement to accept, validate, and persist information from a storefront customer, modify the appearance of a form, add validation and cross-site request forgery (CSRF) protection, and use bindings to process fields

0/9

Prepare for the Exam

Play Today's Certle

Study Community

Ask questions and get the latest info from other B2C Commerce Developer studiers.