`
kirenenko04
  • 浏览: 151059 次
  • 性别: Icon_minigender_2
  • 来自: 上海
社区版块
存档分类
最新评论

Form Framework

 
阅读更多

 

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:

  1. An xml form to define and store the metadata

  2. A pipeline that will validate and process the form

  3. A properties file that contains externalized form labels and possible error messages

  4. An ISML template that will display the form to the user 

 There are 3 objects that interact:

  1. 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.

  2. ISML template: it uses the form metadata fields and actions to show an HTML form to the user.

  3. 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:

  1. Create an xml metadata file that will hold your form data

  2. Create an ISML template that will display a form to a visitor.

  3. Create a pipeline that includes at minimum:

  1. Start node

  2. ClearFormElement pipelet that clears the form object next time you run the pipeline again.

  3. Interaction Continue node that links to the ISML template you created in step 2.

  4. Transition nodes to handle the following scenarios:

分享到:
评论

相关推荐

    ZEND FRAMEWORK 1.11.7 中文参考文档

    Table of Contents •Introduction to Zend Framework •Overview •Installation •Learning Zend Framework •Zend Framework Quick Start •Autoloading in Zend Framework •Plugins in Zend Framework •...

    使用FormValidation进行表单验证

    `FormValidation`是一个强大的JavaScript库,它结合了`jQuery`和`Bootstrap`框架,使得表单验证变得更加简单易用。本文将详细介绍如何使用`FormValidation`进行表单验证,并探讨与`jQuery`和`Bootstrap`的集成。 ...

    Animated Form Switching using Bootstrap Framework.zip

    在本项目"Animated Form Switching using Bootstrap Framework"中,我们将探讨如何利用JavaScript和Bootstrap框架来创建动态表单切换效果。Bootstrap作为最受欢迎的前端开发框架,以其简洁、灵活和响应式设计而闻名...

    NET Compact Framework新动力——加速您的Windows Mobile应用开发(PDF)

    .NET Compact Framework是微软为嵌入式设备和移动设备如Windows Mobile操作系统提供的一个精简版的.NET框架。这个框架使得开发者可以使用.NET Framework的大部分功能,包括C#、VB.NET等编程语言,来创建高效能、功能...

    c#下post multipart/form-data和JSON

    1. 使用`MultipartFormDataContent`:这是.NET Framework或.NET Core中的一个类,用于构建`multipart/form-data`的内容。首先,我们需要创建一个`MultipartFormDataContent`实例,并添加字段和文件: ```csharp ...

    C#2.0 FormDesigner设计器

    C# 2.0 FormDesigner是.NET Framework 2.0时代的一个重要组件,主要用于WinForms应用程序的界面设计。它允许开发者在Visual Studio环境中拖放控件,调整它们的位置、大小以及属性,从而构建用户友好的图形界面。这个...

    FormValidation.js

    **FormValidation.js 知识点详解** `FormValidation.js` 是一个强大且灵活的JavaScript库,专门用于前端表单验证。它提供了丰富的校验规则、样式定制以及对动态添加元素的验证支持,使得开发者能够轻松地创建高效、...

    Bluetooth Framework VCL v5.2.2 (完整源码)

    "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 ...

    play framework api,play! framework api,play api

    - `serialized-form.html`:可能包含了框架中可序列化对象的信息。 - `overview-tree.html`:类的层次结构图,展示框架的包和类之间的关系。 - `allclasses-frame.html`:列出所有类的框架页面,便于查看所有可用的...

    CloseForm关闭另一个窗体

    Windows Forms是.NET Framework提供的一种用于构建桌面应用的用户界面框架。它允许开发者创建交互式、图形化的用户界面。每个窗体(Form)都是一个独立的窗口,可以包含各种控件如按钮、文本框等,以及处理用户交互...

    ZendFramework 1.12.9 代码和文档.rar

    开发者可以根据需要选择和使用特定的组件,例如:数据库访问(Zend_Db)、表单处理(Zend_Form)、缓存管理(Zend_Cache)和邮件服务(Zend_Mail)。这种设计使得项目更易于维护和扩展。 **四、Zend Framework ...

    spring-form.tld

    http://www.springframework.org/tags/form 所需要的spring-form.tld

    一个基于C#实现的通用Win-Form/Web-Form 组件类库及程序例子代码

    该资源是一个针对C#开发者的实用工具包,旨在提供一套通用的Win-Form和Web-Form界面组件。通过使用此类库,开发者可以为桌面应用(Win-Form)和Web应用(Web-Form)创建一致的用户体验,无论是在客户端还是在服务器...

    Form窗体加载模型

    要在Form中使用XNA,你需要创建一个自定义的游戏组件类,继承自`Microsoft.Xna.Framework.GameComponent`。在这个类中,你可以初始化图形设备,设置渲染循环,以及加载和管理3D模型。 3. **图形设备管理**: 在...

    django rest framework vue 实现用户登录详解

    首先,我们要了解Django REST framework以及Vue.js是什么。Django REST framework是一个强大且灵活的工具,用于构建Web API。Vue.js则是一个渐进式JavaScript框架,用于构建用户界面。将这两个技术结合起来实现用户...

    C#中窗体Form的美化

    GDI+(Graphics Device Interface Plus)是.NET Framework提供的图形绘制库,能帮助开发者实现复杂的图形绘制和美化效果。 1. 使用GDI+绘制边框:通过Graphics类的DrawRectangle方法,可以绘制出各种形状和样式的...

    Zend Framework API documentation

    3. **Zend_Form**:用于创建表单,包含字段验证、装饰器和数据处理等功能。 4. **Zend_Feed**:支持 RSS 和 Atom 提要的读取和写入,方便处理新闻聚合和发布。 5. **Zend_View**:视图脚本引擎,负责将数据渲染成 ...

    zend framework 中文版手册(最新)

    4. **表单处理(Zend_Form)**:Zend_Form 提供了强大的表单构建和验证功能,包括元素(Elements)、装饰器(Decorators)和验证规则(Validators)。开发者可以通过手册学习如何创建复杂的用户输入表单。 5. **...

    Oracle Form 实战总结

    Oracle Form是Oracle Application Development Framework (ADF)的一部分,常用于构建基于数据库的桌面和Web应用程序,特别是在Oracle E-Business Suite (EBS)环境中。 Oracle Form Builder是Oracle提供的一款图形化...

Global site tag (gtag.js) - Google Analytics