Forms Framework
The Demandware platform provides a set of tools that help simplify form display and processing. Using the Demandware Forms framework, you can control how consumer-entered values are validated by the application, rendered on a browser and possibly stored on a server.
You need the following four files:
-
An xml form to define and store the metadata
-
A pipeline that will validate and process the form
-
A properties file that contains externalized form labels and possible error messages
-
An ISML template that will display the form to the user
There are 3 objects that interact:
-
XML metadata file: located in the cartridge/forms/default directory. It describes the fields, labels, validation rules and actions that apply when the field is used in an ISML template.
-
ISML template: it uses the form metadata fields and actions to show an HTML form to the user.
-
Object (optional): this object represents a single system or custom object in the pdict, and it can be used to pre-fill the metadata file as well as to store submitted form data to the database.
XML Metadata File
As a developer, you will need to identify which fields a user will need to enter, and what actions can be taken when implementing a form. They will need to be created in an xml form that will set the form field parameters and hold the data for the form.
The form metadata file uses the following XML elements:
Element |
Description |
form |
Required: top level tag that contains all other elements inside <form>…</form> |
field |
Required: Defines data field with many attributes |
options |
Use as a child element inside a field to pre-fill multiple options like months, days, etc |
option |
Use as a child element inside an options element to specify a single option |
action |
Required: Defines a possible action the user might take on the form |
include |
Allows inclusion of one form metadata definition into another. |
list |
Allows inclusion of several items (i.e. collection of addresses) as a single field |
group |
Allows grouping of elements to be invalidated together |
The field element may use the following attributes:
Attributes |
Description |
formid |
Required: unique ID to identify the field for ISML templates and pipelines. |
type |
Required: data type for field |
label |
Usually a key to an externalized string in the forms.properties resource bundle. |
description |
Description for field, might be used in tooltips. |
min-length, max-length |
Restricts the field length for data entry. |
min, max |
Valid range for integer, number and dates. |
range-error 长度错误 |
Message shown if value provided does not fall within the specified range. |
regexp 正则 |
Regular expression for string fields: email, phone, zipcode, etc. |
parse-error 正则错误 |
Message shown when the data entered does not match the regex. Usually a key to an externalized string. |
mandatory 经过后端验证 |
Field is required via server side validation when true. |
missing-error 主键验证错误 |
Message shown if the primary key validation error is generated in a pipeline. |
value-error 主键验证错误解释 |
解释 if a primary key validation error is generated in a pipeline. |
binding |
Used to match field to a persistent object attribute. |
masked |
Specify # of characters to mask. |
format |
Format for display of dates, numbers, etc. |
whitespace |
Specify whitespace handling (none or remove). |
timezoned |
Optional flag for date objects (true or false). |
default-value 预先定义值 |
Pre-defines a value for a field. |
checked-value |
Value when field is checked in a form. |
unchecked-value |
Value when field is unchecked in form. |
Here is an example of a simple form metadata file:
<?xml version="1.0"?>
<form>
<field formid="fname"
label="forms.contactus.firstname.label"
type="string" mandatory="true"
binding="custom.firstName"
max-length="50"/>
<field formid="lname"
label="forms.contactus.lastname.label"
type="string" mandatory="true"
binding="custom.lastName"
max-length="50"/>
<field formid="email"
label="forms.contactus.email.label"
type="string"
mandatory="true"
regexp="^[\w-\.]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,6}$"
parse-error="forms.contactus.email.parse-error"
value-error="forms.contactus.email.value-error"
binding="custom.email"
max-length="50"/>
<action formid="subscribe" valid-form="true"/>
</form>
In the example above, the fields fname, lname and email store the information needed to send a newsletter to a non-registered user. The fields are:
-
Mandatory 后端验证
-
Contain label keys that point to 翻译文件位置
the cartridge/templates/resources/forms.properties file
The email field has an extra requirement: it uses a regular expression to define what an acceptable email can be. Additionally, it specifies a parse-error key which matches an error message in the forms.properties file.
Finally, the action subscribe identifies the possible actions that a user may take on the form. The attribute valid-form="true" means that this form requires validation: 3 required fields plus a valid email format for the last one will be enforced on the server side.
IMPORTANT NOTE
Although it is not a requirement, it is a best practice to use lower-case letters when naming your xml forms(小写字母命名). Pipelines are also xml files and use camel-case naming in SiteGenesis.
ISML Form Template
You define an ISML template with the same tags needed for a valid HTML form: <form>…</form>
You can choose to implement your own form action by specifying a pipeline URL, but that would circumvent(绕过) the Forms Framework. When using the framework you specify an Interaction Continue Node for the form action to post to, as follows:
<form action="${URLUtils.continueURL()}" method="post"
name="SendToFriendForm" id="SendToFriendForm">
The method dw.web.URLUtils.continueURL() ensures that the form gets submitted back to the Interaction Continue Node that displayed the form template.
When creating input fields, you must use the object: pdict.CurrentForms.<form metadata file>.<formid> to reference the specific formid in the form metadata. SiteGenesis has an <isinputfield> custom tag which facilitates(促进) the creation of form fields. For example, to show the fname field from the
newsletter.xml file as a text field in an ISML template, you use:
<isinputfield formfield="${pdict.CurrentForms.newsletter.fname}" type="input">
The custom tag will use the fname formid from the metadata file and build an HTML label using the forms.properties file to pull the text for the
forms.contactus.firstname.label key. It also creates an HTML input field to the right of the label with the necessary client-side JavaScript to enforce required fields:
You can modify the behavior of the <isinputfield> tag since it is a custom tag implemented in the SiteGenesis cartridge.
The final requirement in the ISML template is to implement the button that matches the action in the form metadata. For this we create a standard HTML button with a name attribute that points to a specific action in the form metadata:
<input type="submit" value="${Resource.msg('global.submit','locale',null)}"
name="${pdict.CurrentForms.newsletter.subscribe.htmlName}"/>
Here the pdict.CurrentForms.newsletter.subscribe.htmlName refers to the htmlName property of the action subscribe in the form metadata. In the debugger you can view the value of this property at runtime: dwfrm_newsletter_subscribe. This value identifies a specific action for a specific form, which is necessary when the pipeline ICN determines which form action to process.
Form Pipeline Elements
A pipeline that uses the Demandware forms framework has a very distinctive pattern(独特模式) because it uses the following elements:
-
ClearFormElement pipelet to clear an existing form object in the pdict using a specified form metadata file.
-
InvalidateFormElement invalidates the specified FormElement.
-
ICN to show the ISML form, and to perform server-side validation
-
Transitions that match actions from the form metadata
-
A “next” transition that goes back to the ICN to handle validation errors.
To create a form using the form framework, follow these steps:
-
Create an xml metadata file that will hold your form data
-
Create an ISML template that will display a form to a visitor.
-
Create a pipeline that includes at minimum:
-
Start node
-
ClearFormElement pipelet that clears the form object next time you run the pipeline again.
-
Interaction Continue node that links to the ISML template you created in step 2.
-
Transition nodes to handle the following scenarios:
相关推荐
Table of Contents •Introduction to Zend Framework •Overview •Installation •Learning Zend Framework •Zend Framework Quick Start •Autoloading in Zend Framework •Plugins in Zend Framework •...
"It is as easy as dropping a few components on a form, write a few lines of code and what I could not previous get done in a month was now done in two hours!" says one customer. Applications which ...
MSDN Webcast NET Compact Framework新动力——加速您的Windows Mobile应用开发 PDF
http://www.springframework.org/tags/form 所需要的spring-form.tld
它覆盖了在Web Form、Windows Form、ADO.NET和ASP.NET中使用的新的Web和数据库访问技术。《Visual Studio.NET Framework技术内幕》还包括了XML重点,比如SOAP协议的讲解,因为它将广泛应用于分布式应用程序组件相互...
它覆盖了在Web Form、Windows Form、ADO.NET和ASP.NET中使用的新的Web和数据库访问技术。《Visual Studio.NET Framework技术内幕》还包括了XML重点,比如SOAP协议的讲解,因为它将广泛应用于分布式应用程序组件相互...
security models in form of code-based security modules. The design ofASFreflects lessons learned from the literature on established security frameworks (such as Linux Security Modules or the BSD MAC ...
JavaScript
1. Introduction to Zend Framework 1.1. 概述 1.2. 安装 2. Zend_Acl 2.1. 简介 2.1.1. 关于资源(Resource) 2.1.2. 关于角色(Role) 2.1.3. 创建访问控制列表(ACL) 2.1.4. 注册角色(Role) 2.1.5. 定义访问...
Form a Nexus around a new or existing product and learn how that Nexus sets goals and plans its work Run Sprints within a Nexus, provide transparency into progress, conduct effective Nexus Sprint ...
本文实例讲述了Zend Framework教程之Zend_Form组件实现表单提交并显示错误提示的方法。分享给大家供大家参考,具体如下: 同时公司又要开发一个群组功能..我也就想运用一下Zend_Form来实现创建群组的功能.主要还是...
介绍 JGoodies FORM FRAMWORK 的不错的资料
Framework “PMI” and the PMI logo are service and trademarks registered in the United States and other nations; “PMP” and the PMP logo are certification marks registered in the United States and ...
The view can take the form of a String * view name which will need to be resolved by a ViewResolver object; * alternatively a View object can be specified directly. The model * is a Map, allowing ...
Guna UI 是一种用于 .NET 平台的现代用户界面(UI)控件库,旨在帮助开发人员快速创建漂亮、交互性强、功能丰富的桌面应用程序。Guna UI 提供了一系列高度可定制的控件,使开发人员能够以简单的方式构建现代化的用户...
#Robot-Framework-Formatter源代码Selenium IDE:Robot Framework Formatter seleniumLibrary.robot: : 这些是运行Robot Framework的常用关键字,您可以编写一些关键字来改善这一点。 用户指南: 安装...
robotframework接⼝测试案例 1.关键字:post请求 *** Settings *** Library RequestsLibrary *** Keywords *** post.request [Arguments] ${url} ${api} ${data} ${headers} [Documentation] post请求封装 #创建...
如果您仅仅是需要运行该软件,只需要安装上.NET Framework 2.0即可。然后打开Program下的CheckWebLogic.exe文件即可使用。在界面上输入要监控的WebLogic地址,以及登录名和密码,Interval为每隔多长时间请求一次...
Flutter FormBuilder-flutter_form_builder 该软件包通过删除构建表单,验证字段,对更改做出React以及收集最终用户输入所需的样板,帮助在Flutter中创建数据收集表单。 简单用法 要使用此插件,请添加flutter_form...