Actions

Difference between revisions of "Server-side form validation"

From Joomla! Documentation

m (Validation rules: spelling corrections)
m (Inuse being used not inuse)
 
(4 intermediate revisions by 3 users not shown)
Line 8: Line 8:
  
 
== Validation rules ==
 
== Validation rules ==
{| class="wikitable" style="vertical-align:top; border:1px solid Sienna; background-color:Cornsilk;"
+
{| class="wikitable sortable"  
|- style="background-color:Wheat; font-weight:bold; text-align: left;"
+
|-  
|Rule
+
!Rule
|Description
+
!Description
|Availability
+
!Availability
 
|-
 
|-
 
|
 
|
 
'''boolean'''
 
'''boolean'''
| Todo
+
| Accepts only the values '0', '1', 'true' or 'false' (case-insensitive).
| Todo (e.g. {{JVer|1.5}} and newer)
+
| {{JVer|11.1}} and newer
 
|-
 
|-
 
|
 
|
 
'''color'''
 
'''color'''
| Todo
+
| Accepts only empty values (converted to '#000000') and strings in the form '#RGB' or '#RRGGBB' where R, G, and B are hex values.
| Todo (e.g. {{JVer|1.5}} and newer)
+
| {{JVer|11.2}} and newer
 
+
 
|-
 
|-
 
|
 
|
 
'''email'''
 
'''email'''
| Todo
+
| Accepts an email address satisfies a basic syntax check in the pattern of "x@y.zz", with no invalid characters.
| Todo (e.g. {{JVer|1.5}} and newer)
+
| {{JVer|11.1}} and newer
 
+
 
|-
 
|-
 
|
 
|
 
'''equals'''
 
'''equals'''
| Todo
+
| Requires the value to be the same as that held in the field named "field", eg: <source lang="xml"><input type="text" name="email_check" validate="equals" field="email" /></source>
| Todo (e.g. {{JVer|1.5}} and newer)
+
| {{JVer|11.1}} and newer
 
+
 
|-
 
|-
 
|
 
|
 
'''options'''
 
'''options'''
| Requires the value entered be one of the options in a field of type="list"
+
| Requires the value entered be one of the options in an element of type="list": that is, that the element is a select list.
 
| {{JVer|11.1}} and newer  
 
| {{JVer|11.1}} and newer  
 
 
|-
 
|-
 
|
 
|
 
'''rules'''
 
'''rules'''
 
| Todo
 
| Todo
| Todo (e.g. {{JVer|1.5}} and newer)
+
| {{JVer|11.1}} and newer  
 
+
 
|-
 
|-
 
|
 
|
 
'''tel'''
 
'''tel'''
| Telephone number (nanpa, ITU-T T-REC-E.164 or ietf rfc4933)
+
| Requires the value to be a Telephone number complying with the standards of nanpa, ITU-T T-REC-E.164 or ietf rfc4933.
 
| {{JVer|11.1}} and newer
 
| {{JVer|11.1}} and newer
 
 
|-
 
|-
 
|
 
|
 
'''url'''
 
'''url'''
| Todo
+
| Validates that the value is a URL with a valid scheme (which can be restricted by the optional comma-separated field 'scheme'), and passes a basic syntax check. eg: <source lang="xml"><input type="text" name="link" validate="url" scheme="http,https,mailto" /></source>
| Todo (e.g. {{JVer|1.5}} and newer)
+
| {{JVer|11.1}} and newer
 
+
 
|-
 
|-
|
+
|  
 
'''username'''
 
'''username'''
| Todo
+
| Validates that the value does NOT appear as a username on the system; that is, that it is a valid new username. Does not syntax check it as a valid name.
| Todo (e.g. {{JVer|1.5}} and newer)
+
| {{JVer|11.1}} and newer
 
+
 
|-
 
|-
 
|}
 
|}
  
 +
You can find the specific implementation of these rules in \libraries\joomla\form\form.php - validation begins in the function validate(), moves to validateField(), which then calls the respective validation functions of \libraries\joomla\form\rules\*.php
 +
 +
==Server- or Client-side validation?==
 +
[[Form validation]]
  
 
[[Category:Development]] [[Category:JForm]] [[Category:Form_fields]]
 
[[Category:Development]] [[Category:JForm]] [[Category:Form_fields]]

Latest revision as of 18:36, 5 June 2014

Quill icon.png
Content is Incomplete

This article or section is incomplete, which means it may be lacking information. You are welcome to assist in its completion by editing it as well. If this article or section has not been edited in several days, please consider helping complete the content.
This article was last edited by Tom Hutchison (talk| contribs) 2 months ago. (Purge)

Copyedit.png
This Article Needs Your Help

This article is tagged because it NEEDS REVIEW. You can help the Joomla! Documentation Wiki by contributing to it.
More pages that need help similar to this one are here. NOTE-If you feel the need is satistified, please remove this notice.


After submitting a form, you should validate your data. In Joomla this can be done via the JForm validate method (normally called in the controller via the model JModelForm).

Unlike client-side validation, the validation uses html attributes to do its validation. There is the attribute required ("true" or "required") which makes a field required and the attribute validate with a joomla or custom rule value.

E.g. field in a joomla form xml

<field name="email" type="text" class="inputbox" description="Fill in your E-mail" label="E-mail" required="true" validate="email" size="30" />

Validation rules

Rule Description Availability

boolean

Accepts only the values '0', '1', 'true' or 'false' (case-insensitive). Joomla 11.1 and newer

color

Accepts only empty values (converted to '#000000') and strings in the form '#RGB' or '#RRGGBB' where R, G, and B are hex values. Joomla 11.2 and newer

email

Accepts an email address satisfies a basic syntax check in the pattern of "x@y.zz", with no invalid characters. Joomla 11.1 and newer

equals

Requires the value to be the same as that held in the field named "field", eg:
<input type="text" name="email_check" validate="equals" field="email" />
Joomla 11.1 and newer

options

Requires the value entered be one of the options in an element of type="list": that is, that the element is a select list. Joomla 11.1 and newer

rules

Todo Joomla 11.1 and newer

tel

Requires the value to be a Telephone number complying with the standards of nanpa, ITU-T T-REC-E.164 or ietf rfc4933. Joomla 11.1 and newer

url

Validates that the value is a URL with a valid scheme (which can be restricted by the optional comma-separated field 'scheme'), and passes a basic syntax check. eg:
<input type="text" name="link" validate="url" scheme="http,https,mailto" />
Joomla 11.1 and newer

username

Validates that the value does NOT appear as a username on the system; that is, that it is a valid new username. Does not syntax check it as a valid name. Joomla 11.1 and newer

You can find the specific implementation of these rules in \libraries\joomla\form\form.php - validation begins in the function validate(), moves to validateField(), which then calls the respective validation functions of \libraries\joomla\form\rules\*.php

Server- or Client-side validation?

Form validation