Difference between revisions of "Form field"

From Joomla! Documentation

(Change 1.6 to 2.5)
(Add <fieldset name="basic"> to note about defining form fields in an extension configuration)
Line 4: Line 4:
 
In addition to being a flexible page creation tool, JFormFields are used by Joomla! to allow [[Administrator (User)|administrators]] to configure Joomla! or its extensions without changing the underlying code. In Joomla! 1.5, this was handled by the now deprecated [[JParameter/1.5|JParameter]] and [[JElement/1.5|JElement]] classes.
 
In addition to being a flexible page creation tool, JFormFields are used by Joomla! to allow [[Administrator (User)|administrators]] to configure Joomla! or its extensions without changing the underlying code. In Joomla! 1.5, this was handled by the now deprecated [[JParameter/1.5|JParameter]] and [[JElement/1.5|JElement]] classes.
  
To define form fields in the configuration of an extension, you must include them into the <code><fields name="params"></code> section of the <code><config></code> element in your [[Manifest files|XML manifest file]].
+
To define form fields in the configuration of an extension, you must include them in a named fieldset, such as <code><fieldset name="basic"></code>, that is within the <code><fields name="params"></code> section of the <code><config></code> element in your [[Manifest files|XML manifest file]].
 
</onlyinclude>
 
</onlyinclude>
  

Revision as of 08:41, 22 May 2013

Form fields are fields in a HTML <form>. Joomla! 2.5 Joomla 2.5 and newer supply the JForm class to conveniently and flexibly create forms with a large amount of form fields. Each form field type is a subclass of JFormField.

In addition to being a flexible page creation tool, JFormFields are used by Joomla! to allow administrators to configure Joomla! or its extensions without changing the underlying code. In Joomla! 1.5, this was handled by the now deprecated JParameter and JElement classes.

To define form fields in the configuration of an extension, you must include them in a named fieldset, such as <fieldset name="basic">, that is within the <fields name="params"> section of the <config> element in your XML manifest file.


Form validation[edit]

<translate> Joomla has client-side and server-side form validation capabilities.

Server side validation is essential since everything before that can be overridden on the user side by hackers. However client-side is the most user-friendly validation, so using both is considered best practice.</translate>

<translate>==Client-side Validation== </translate> <translate> ...is done via JavaScript while the user is filling in the form fields.

It uses the HTML classes required' and validate-[xxx] (with [xxx] being a Joomla or custom rule; e.g. validate-numeric)</translate>

<translate> More here: Client-side form validation</translate>

<translate>==Server-side validation== </translate> <translate> ...is done after having submitted the form and will normally return to the form when not validated with some extra messages.

It uses the HTML attributes required ("true" or "required") and validate (with the value being a Joomla or custom rule, e.g. validate="email")</translate>

<translate> More here: Server-side form validation</translate>


Standard form field types[edit]

<translate> Numerous types of form field are built into Joomla!. The following table lists these standard types and their availability. Use the single-page reference if you want to print all existing form field documentation.</translate>

<translate> Joomla 1.5 Please note that many of these fields are available as parameter types in Joomla! 1.5. For a list of parameter types, see J1.5:Standard parameter types. For a comparison between form field and parameter types, see Standard form field and parameter types.</translate>

<translate>

Type</translate>

<translate>

Description</translate>

<translate>

Availability</translate>

<translate>

accessiblemedia</translate>

<translate>

provides modal access to the media manager for insertion of images with upload for users with appropriate permissions and a text field for adding a alternative text.</translate>

Joomla 4.0 <translate>

and newer</translate>

<translate>

accesslevel</translate>

<translate>

provides a drop down list of viewing access levels.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

cachehandler</translate>

<translate>

provides a list of available cache handling options.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

calendar</translate>

<translate>

provides a text box for entry of a date. An icon next to the text box provides a link to a pop-up calendar, which can also be used to enter the date value.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

captcha</translate>

<translate>

provides the use of a captcha plugin.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

category</translate>

<translate>

provides a drop down list of categories for an extension.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

checkbox</translate>

<translate>

provides a single checkbox to be checked or unchecked</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

checkboxes</translate>

<translate>

provides unlimited checkboxes that can be used for multi-select.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

Chrome Style</translate>

<translate>

provides a list of template chrome style options grouped by template.</translate>

Joomla 3.0 <translate>

and newer</translate>

<translate>

color</translate>

<translate>

provides a color picker when clicking the input box.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

Content Language</translate>

<translate>

Provides a list of content languages.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

Content Type</translate>

<translate>

Provides a list of content types.</translate>

Joomla 3.1 <translate>

and newer</translate>

<translate>

combo</translate>

<translate>

provides a combo box field.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

componentlayout</translate>

<translate>

provides a grouped list of core and template alternative layouts for a component item.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

contentlanguage</translate>

<translate>

provides a list of installed content languages for use in conjunction with the language switcher plugin.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

Database Connection</translate>

<translate>

Provides a list of available database connections, optionally limiting to a given list.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

editor</translate>

<translate>

provides an editor area field.</translate>

Joomla 1.6 <translate>

and newer</translate>

<translate>

editors</translate>

<translate>

Provides a drop down list of the available WYSIWYG editors. Since Joomla 2.5 use plugins form field instead.</translate>

Joomla 1.6
<translate>

email</translate>

<translate>

provides an email field.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

file</translate>

<translate>

Provides an input field for files</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

filelist</translate>

<translate>

provides a drop down list of files from a specified directory.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

folderlist</translate>

<translate>

provides a drop down list of folders from a specified directory.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

groupedlist</translate>

<translate>

provides a drop down list of items organized into groups.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

header tag</translate>

<translate>

provides a drop down list of the header tags (h1-h6)</translate>.

Joomla 3.0 <translate>

and newer</translate>

<translate>

helpsite</translate>

<translate>

provides a drop down list of the help sites for your Joomla installation.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

hidden</translate>

<translate>

provides a hidden field for saving a form field whose value cannot be altered directly by a user in the Administrator (it can be altered in code or by editing the params.ini file).</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

imagelist</translate>

<translate>

provides a drop down list of image files in a specified directory.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

integer</translate>

<translate>

provides a drop down list of integers between a minimum and maximum.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

language</translate>

<translate>

provides a drop down list of the installed languages for the Front-end or Back-end.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

list</translate>

<translate>

provides a drop down list of custom-defined entries.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

media</translate>

<translate>

provides modal access to the media manager for insertion of images with upload for users with appropriate permissions.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

menu</translate>

<translate>

provides a drop down list of the available menus from your Joomla site.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

Menu Item</translate>

<translate>

provides a drop down list of the available menu items from your Joomla site.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate> meter</translate> <translate>

Provides a meter to show value in a range.</translate>

Joomla 3.2 <translate>

and newer</translate>

<translate>

Module Layout</translate>

<translate>

provides a list of alternative layout for a module grouped by core and template.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

Module Order</translate>

<translate>

Provides a drop down to set the ordering of module in a given position</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

Module Position</translate>

<translate>

provides a text input to set the position of a module.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

Module Tag</translate>

<translate>

provides a list of html5 elements (used to wrap a module in).</translate>

Joomla 3.0 <translate>

and newer</translate>

<translate>

note</translate>

<translate>

supports a one line text field.</translate>

Joomla 3.1 <translate>

and newer</translate>

<translate>

number</translate>

<translate>

Provides a one line text box with up-down handles to set a number in the field.</translate>

Joomla 3.2 <translate>

and newer</translate>

<translate>

password</translate>

<translate>

provides a text box for entry of a password. The password characters will be obscured as they are entered.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

plugins</translate>

<translate>

provides a list of plugins from a given folder.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

predefinedlist</translate>

<translate>

Form Field to load a list of predefined values.</translate>

Joomla 3.2 <translate>

and newer</translate>

<translate>

radio</translate>

<translate>

provides radio buttons to select different options.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

range</translate>

<translate>

Provides a horizontal scroll bar to specify a value in a range.</translate>

Joomla 3.2 <translate>

and newer</translate>

<translate>

repeatable</translate>

<translate>

Allows form fields which can have as many options as the user desires.</translate>

Joomla 3.2 <translate>

and newer</translate>

<translate>

rules</translate>

<translate>

provides a matrix of group by action options for managing access control. Display depends on context.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

sessionhandler</translate>

<translate>

provides a drop down list of session handler options.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

spacer</translate>

<translate>

provides a visual separator between form fields. It is purely a visual aid and no value is stored.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

sql</translate>

<translate>

provides a drop down list of entries obtained by running a query on the Joomla Database. The first results column returned by the query provides the values for the drop down box.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

subform</translate>

<translate>

provides a way to use XML forms inside each other or reuse your existing forms inside your current form.</translate>

Joomla 3.6 <translate>

and newer</translate>

<translate>

tag</translate>

<translate>

provides an entry point for tags (either AJAX or Nested).</translate>

Joomla 3.1 <translate>

and newer</translate>

<translate>

tel</translate>

<translate>

provides an input field for a telephone number.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

templatestyle</translate>

<translate>

provides a drop down list of template styles.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

text</translate>

<translate>

provides a text box for data entry.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

textarea</translate>

<translate>

provides a text area for entry of multi-line text.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

timezone</translate>

<translate>

provides a drop down list of time zones.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

URL</translate>

<translate>

provides a URL text input field.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

user</translate>

<translate>

Field to select a user from a modal list. Displays User Name and stores User ID</translate>

Joomla 1.6 <translate>

and newer</translate>

<translate> useractive</translate> <translate>

Field to show a list of available user active statuses.</translate>

Joomla 3.2 <translate>

and newer</translate>

<translate>

usergroup</translate>

<translate>

provides a drop down list of user groups. Since Joomla 3.2 use usergrouplist instead.</translate>

Joomla 2.5 <translate>

and newer</translate>

<translate>

usergrouplist</translate>

<translate>

Field to load a drop down list of available user groups. Replaces usergroup form field type.</translate>

Joomla 3.2 <translate>

and newer</translate>

<translate> userstate</translate> <translate>

Field to load a list of available users statuses.</translate>

Joomla 3.2 <translate>

and newer</translate>


Custom form field types[edit]

An extension can define its own form field types, which can then be used in its own forms or forms created by another extension. See Creating a custom form field type for instructions.

Modal form field types[edit]

If you have a field with a lot of values that don't fit a selection box, you can always make a modal form field that will allow the user to pick an item from a modal page with a table, filtering options, etc. (jut like any administrator table, e.g. "Articles") See Creating a modal form field