form-controls
文件大小: unknow
源码售价: 5 个金币 积分规则     积分充值
资源说明:[Symphony 2] An XSLT utility to create powerful HTML forms with Symphony Events
# Form Controls
An XSLT utility to create powerful HTML forms with [Symphony](http://symphony-cms.com)

## What is it?
Form Controls is a suite of XSL templates for rapidly building forms that are tightly coupled with Symphony Events. The core aim is to make forms easier to build so that the developer can spend less time on validation and checking posted data, and more time on adding the extra layer of polish that make forms more usable.

Form Controls provides the following functionality:

* templates to render all common HTML form control elements
* pre-populate controls with static or dynamic data
* persist posted values from Events
* associate and optionally wrap with labels
* provides HTML hooks when field is invalid (class attribute)
* provides powerful validation messages and error response

## Download
Form Controls (`form-controls.xsl`) is a single XSLT file and can be downloaded from Github:


## Installing the utility
Add the `form-controls.xsl` file to your `/workspace/utilities` folder alongside the [other cool XSLT utilities](http://symphony21.com/downloads/xslt/) you know and love.

On the page in which you are building the form, import the XSL file:

	

Form Controls uses some functions not available to XSLT 1.0, therefore you will need to have the [EXSLT library](http://exslt.org/) installed (you should do already) and you will need to add the EXSLT namespace to your page. Additionally Form Controls adds all templates and variables to `form` namespace so as not to clash with other templates in your site. After including these two namespaces, your page `stylesheet` element should look something like this:

	

The `extension-element-prefixes` attribute prevents these namespaces being added to your HTML elements when the page is rendered.

## Supported form controls
Form Controls supports all field types native to Symphony (input, textarea, select) and adds a few of its own too. It can generate the following:

* Label
* Input (text, password, file)
* Textarea
* Checkbox
* Radio
* Select (including multi-select)
* Radiobutton List
* Checkbox List
* Validation Summary (list of error messages)

Form Controls assumes you are submitting to a front-end event in Symphony.

## Most basic example
Submits to an event (`save-post`) derived from a Posts section. Create a new page and attach the `Save Post` event to it. Paste the following XSLT into your page replacing the default contents:

	
	

	
	

	
	

	

		
Create new post
This will generate HTML akin to the following (just the `fieldset` included, my indenting):
Create new post
On form submit you will also see a validation summary — either a success message, or a list of missing or invalid fields. ## Template examples Here are examples outlining the full range of control templates. ### form:event This variable should be created globally, outside of the page templates. It should select the event node created by the event you are posting to. ### form:label Renders an HTML `label` element that can be explicitly assigned to another form element. Can be wrapped around other controls. #### Parameters * `for` (optional, string): Handle of a Symphony field name that this label is associated with * `text` (optional, string): Text value of the label. Defaults to field name ($for value) * `child` (optional, XML): Places this XML inside the label, for wrapping elements with the label * `child-position` (optional, string): Place the child before or after the label text. Defaults to "after" * `class` (optional, string): Value of the HTML @class attribute * `template` (optional, XML): HTML template for label contents. Use `$` as placeholder for label text * `section` (optional, string): Use with EventEx to change "fields[...]" to a section handle * `event` (optional, XPath): XPath expression to the specific event within the page node #### Example $ * ### form:input Renders an HTML text `input` element with support for `password` and `file` types. #### Parameters * `handle` (mandatory, string): Handle of the field name * `value` (optional, string): Initial value of form control. Will not work for `file` inputs. * `type` (optional, string): Type attribute value ("text", "password" "file"). Defaults to "text" * `class` (optional, string): Class attribute value * `title` (optional, string): Title attribute value * `size` (optional, string): Size attribute value * `maxlength` (optional, string): Maxlength attribute value * `autocomplete` (optional, string): Autocomplete attribute value ("off"). Not set by default * `placeholder` (optional, string): Placeholder text. Not set by default * `section` (optional, string): Use with EventEx to change "fields[...]" to a section handle * `event` (optional, XPath): XPath expression to the specific event within the page node #### Example ### form:textarea Renders an HTML `textarea` element. #### Parameters * `handle` (mandatory, string): Handle of the field name * `value` (optional, string): Contents of the textarea * `class` (optional, string): Class attribute value * `rows` (optional, string): Rows attribute value * `cols` (optional, string): cols attribute value * `section` (optional, string): Use with EventEx to change "fields[...]" to a section handle * `event` (optional, XPath): XPath expression to the specific event within the page node #### Example ### form:checkbox Renders an HTML checkbox `input` element. If a checkbox is not checked, its value is never sent in the POST array to the event. For this reason a hidden field with the same name, and a value of "no" will be rendered just before the checkbox. Ticking the checkbox will override this "no" value. #### Parameters * `handle` (mandatory, string): Handle of the field name * `checked` (optional, string): Initial checked state ("yes", "no"). Defaults to "no" * `checked-by-default` (optional, string): When there is no initial $checked value (a fresh form), check by default ("yes", "no"). Defaults to "no" * `class` (optional, string): Class attribute value * `title` (optional, string): Title attribute value * `section` (optional, string): Use with EventEx to change "fields[...]" to a section handle * `event` (optional, XPath): XPath expression to the specific event within the page node * `allow-multiple` (optional, string): Internal use only ("yes", "no"). Whether checkbox is part of a checkbox list. Defaults to "no" * `allow-multiple-value` (optional, string): Internal use only. Overrides default "yes" value when part of a checkbox list #### Example ### form:radio Renders an HTML radio `input` element. Could be used to save values to an Input or Select Box field. #### Parameters * `handle` (mandatory, string): Handle of the field name * `value` (optional, string): The selected value for this radio sent when the form is submitted * `existing-value` (optional, string): An initial value. Selects radio if it matches $value * `checked-by-default` (optional, string): When there is no initial $existing-value (a fresh form), select by default ("yes", "no"). Defaults to "no" * `class` (optional, string): Class attribute value * `title` (optional, string): Title attribute value * `type` (optional, string): Internal use only ("radio", "checkbox"). Defaults to "radio" * `section` (optional, string): Use with EventEx to change "fields[...]" to a section handle * `event` (optional, XPath): XPath expression to the specific event within the page node * `allow-multiple` (optional, string): Internal use only ("yes", "no"). Whether control is part of a radio/checkbox list. Defaults to "no" #### Example ### form:select Renders an HTML `select` element. Has several presets to build commonly-used sets of options, and supports many formats to create additional options. #### Parameters * `handle` (mandatory, string): Handle of the field name * `options` (mandatory, XPath/XML): Options to build a list of

本源码包内暂不包含可直接显示的源代码文件,请下载源码包。