Standard Joomla XML field type - Email
The email field type creates an input element for email addresses. Unlike a standard text field, it uses the HTML5 type="email" attribute, which provides:
- Native email format validation in modern browsers.
- An optimized keyboard on mobile devices (with quick access to @ and .).
- Server-side data validation upon form submission.
Field Attributes
Below are the main attributes supported by the URL field type. Use them inside the <field> tag of your XML manifest.
| Attribute | Type | Description |
|---|---|---|
name
|
string | Required. The unique field identifier. Used to retrieve data in PHP ($form->getValue('name')) and to generate the HTML name attribute. Must contain only Latin letters, numbers, and underscores. |
type
|
string | Required. The field type. For this case, the value is always email. It renders as , which enables native HTML5 validation and the mobile keyboard. |
label
|
string | The field label displayed next to the input. Supports translation strings (e.g., JGLOBAL_EMAIL). In Joomla 4-6, it is automatically associated with the field via accessibility (ARIA) attributes. |
required
|
boolean | If true, the field becomes required. It adds an asterisk (*) to the label and the required attribute to the HTML. In Joomla 4-6, it also adds aria-required="true" for screen readers. |
validate
|
string | The name of the validation rule. For email, use validate="email". It ensures format validation on both the server and client sides. |
filter
|
string | Data sanitization filter applied before saving to the database. Critical for security. It is recommended to use filter="email", which removes all invalid characters. If not specified, data may be saved "as is," which is dangerous. |
default
|
string | The default value inserted into the field when creating a new record (if the field is empty). Can be a string or a translation constant. |
hint
|
string | Hint text inside the field (HTML5 placeholder). Joomla 4-6: works natively. Joomla 3: not supported by standard layouts (requires a template override or JS workaround). |
description
|
string | Additional description. Joomla 3: displayed as a tooltip. Joomla 4-6: behavior depends on the form layout (often ignored or displayed as small text below the field). For short hints, it is better to use hint. |
class
|
string | CSS classes for the tag. In Joomla 4-6, base classes (e.g., form-control) are added automatically, but you can add your own custom classes here. |
labelclass
|
string | CSS classes for the |
size
|
integer | The visible width of the field in characters (HTML5 size attribute). In modern responsive templates (J4-J6), it is better to control width via CSS/Bootstrap rather than using this attribute. |
maxlength
|
integer | The maximum number of characters allowed for input. The browser blocks further input, and the server also truncates the data during filtering. |
readonly
|
boolean | If true, the field cannot be edited, but its value is sent to the server upon form submission. Use this to display system data that should not be changed but must be saved. |
disabled
|
boolean | If true, the field is disabled and visually dimmed. Its value is NOT sent to the server. |
autocomplete
|
string | Controls browser autocomplete. Values: off, on, email, new-email. In Joomla 6, it is recommended to explicitly specify autocomplete="email" to improve UX and password manager functionality. |
autofocus
|
boolean | If true, the input focus is set to the field immediately after the page loads. Only one field per page can have this attribute. |
showon
|
string | Condition for dynamic field display. Example: showon="send_copy:1" (show if the send_copy field equals 1). Works in J3 (via JS) and natively in J4-J6. A very powerful tool for complex forms. |
spellcheck
|
boolean | Enables (true) or disables (false) spell checking. For email fields, it is recommended to set this to false so that the browser does not underline addresses in red. |
pattern
|
string | Regular expression (Regex) for additional client-side validation (HTML5). Complements validate but does not replace server-side validation. |
Visual Examples
Below are screenshots showing how the field appears in different Joomla versions and admin panel themes.
XML Usage Example
Add this code inside your XML manifest tag. The type="email" attribute automatically enables browser-based email format validation and adapts the keyboard on mobile devices.
<field
name="email"
type="email"
label="Email Address"
description="Enter your email address"/>
Retrieving Value in PHP
To retrieve data from form fields in Joomla, the JInput object is used. It ensures secure filtering of input data. Below are examples of retrieving an email address for modern versions (J4/J5/J6) and legacy versions (J3). Note the use of the get() method with the 'email' filter. This filter automatically removes invalid characters and checks the basic email format.
// --- JOOMLA 4/5/6 VARIANT (Modern) ---
use JoomlaCMSFactory;
// Get the input object via Factory
$input = Factory::getApplication()->input;
// Get the email.
// The third argument 'email' applies the built-in sanitization filter
$myEmail = $input->get('my_email_field', '', 'email');
// --- JOOMLA 3 VARIANT (Legacy) ---
// JFactory was used in J3
$input = JFactory::getApplication()->input;
$myEmail = $input->get('my_email_field', '', 'email');
// OR the old way (not recommended, but found in legacy code):
$myEmail = JRequest::getVar('my_email_field', '', 'get', 'email');
// --- SAFE OUTPUT ---
// Always escape output to protect against XSS
echo htmlspecialchars($myEmail, ENT_QUOTES, 'UTF-8');
// Example usage in a mailto link:
if (!empty($myEmail)) {
echo '<a href="mailto:' . htmlspecialchars($myEmail, ENT_QUOTES, 'UTF-8') . '">'
. htmlspecialchars($myEmail, ENT_QUOTES, 'UTF-8') . '</a>';
}
In the examples above, the 'email' filter is used as the third argument of the get() method. This is critical for security: the filter automatically removes any characters that do not comply with the email address standard, preventing injection attempts. Always use the htmlspecialchars() function when outputting data to the page to avoid XSS attacks. If the field might be empty, it is recommended to add a !empty($myEmail) check before using the value.
Tip: Always explicitly specify the filter="email" attribute in your XML markup. Although the type="email" field type provides client-side format validation (in the browser), a server-side filter is necessary to sanitize data before saving it to the database, protecting your site from incorrect entries and potential vulnerabilities.
Common Pitfalls
-
No getEmail() method: The JInput object does not have a dedicated $input->getEmail() method, unlike $input->getUrl() or $input->getInt(). Developers often waste time looking for it. The correct way to retrieve data is to use the universal get() method with the 'email' filter: $input->get('field_name', '', 'email').
-
Difference between readonly and disabled: If you set the attribute disabled="true", the field value will not be sent to the server upon form submission, and the data will not be saved. If your goal is to prevent editing while still saving the value to the database, be sure to use readonly="true". This is a common mistake when configuring profile forms.
-
Hint attribute specifics in Joomla 3: The hint attribute (placeholder text inside the field) works natively only in Joomla 4 and later. In Joomla 3, standard layouts ignore this attribute. If support for J3 is critical, you will need to implement the hint via a layout override or JavaScript; otherwise, users will not see it.