Standard Joomla XML Field Type - Number

The standard Joomla XML number field is based on the HTML5 <input type="number"> element and renders an input field with increment/decrement buttons for adjusting numeric values. It is designed for entering numbers, supports range and step configuration (via the min, max, and step attributes), and includes built-in data format validation. This field works correctly across all supported Joomla versions, including the legacy 3.x branch as well as modern releases 4, 5, and 6.

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. Unique system field identifier. Used for saving data and retrieving the value in PHP ($input->get('name')).
type string Required. Must be set to "number". Defines the field as an HTML5 numeric input field.
label string Field title visible to the user in the admin area or on the site. Can be a language constant (e.g., COM_EXAMPLE_NUMBER_LABEL).
description string Hint text. In Joomla 3, it appears as a tooltip when hovering over the label; in J4/5/6, it may be displayed below the field or in a popup window.
default int / float Default value. Sets the initial number in the field if it is empty or new.
min int / float Minimum allowed value. The browser will not allow the form to be submitted if the entered number is less than this value.
max int / float Maximum allowed value. Restricts the upper bound of the number input.
step int / float / any Step value for increment/decrement arrows. Defaults to 1 (integers). For decimals, specify 0.01 or any.
required bool Makes the field required. If true, the browser will block form submission if the field is empty.
readonly bool Blocks editing. The user sees the value but cannot change it. Data is sent to the server.
filter string Data filter for PHP. It is recommended to explicitly specify "int" (integers) or "float" (decimals) for type safety.
class string Additional CSS classes for the tag. Allows customization of the appearance via styles.
hint string Hint text (placeholder) inside the empty field. Disappears when typing begins. Do not confuse with description.
showon string Condition for field display. The field will appear only if another field has a specific value (e.g., showon="other_field:1").
disabled bool Disables the field. It becomes grayed out and is not sent to the server when the form is saved.
autocomplete string Controls browser autocomplete. Use "off" to disable suggestions of previous values.
autofocus bool Automatically sets the cursor focus on this field when the page loads.

Visual Examples

Below are screenshots showing how the field appears in different Joomla versions and admin panel themes.

Joomla 3 Isis
Number Field in Joomla 3.x Settings (Isis Admin Template)
Classic field appearance in the Isis template.
Joomla 4 / 5 / 6 Cassiopeia (Light)
Visual display of the Number field in Joomla 4/5/6 - Cassiopeia admin template light theme
Modern Cassiopeia design. Light theme.
Joomla 4 / 5 / 6 Cassiopeia (Dark)
Visual display of the Number field in Joomla 4/5/6 - Cassiopeia admin template dark theme
Admin dark theme. High-contrast text and dark background.

XML Usage Example

Add this code inside your XML manifest tag. The type="number" attribute automatically activates browser-based validation of the numeric format and displays controls for adjusting the value.

<field
    name="my_number"
    type="number"
    label="Number of Items"
    description="Enter an integer between 1 and 100."
    default="10"
    min="1"
    max="100"
    step="1"/>

Retrieving Value in PHP

To retrieve the field value in PHP code, use the input object. Applying int or float filters ensures that data is cast to a numeric type and stripped of extraneous characters, making it safe for further calculations.

// --- JOOMLA 4 / 5 / 6 (Modern) ---
use JoomlaCMSFactory;

// Get the input object via Factory
$input = Factory::getApplication()->input;

// getInt() automatically casts the value to an integer.
// If you need a float, use getFloat('my_number_field', 0.0)
$myNumber = $input->getInt('my_number_field', 0);


// --- JOOMLA 3.x (Legacy) ---
// JFactory was used in J3
$input = JFactory::getApplication()->input;

// The second argument 'int' ensures filtering and casting to an integer
$myNumber = $input->get('my_number_field', 0, 'int'); 

// OR the old way (not recommended, but found in legacy code):
$myNumber = JRequest::getVar('my_number_field', 0, 'get', 'int');


// --- IMPORTANT NOTE ON DATA TYPES ---
// The getInt() and getFloat() methods guarantee that you receive a numeric type (int/float),
// not a string. This is safe for mathematical operations.

// Example usage in a condition or math operation:
if ($myNumber > 10) {
    $result = $myNumber * 2;
    echo "Result: " . $result;
}

// If you used the 'cmd' or 'string' filter (which is bad for numbers),
// be sure to explicitly cast the type:
$unsafeValue = $input->get('my_number_field', '0', 'string');
$safeInt = (int) $unsafeValue; 

Note that the getInt() and getFloat() methods do not just retrieve data, but also forcibly cast it to the corresponding PHP numeric type. This ensures correct mathematical operations and protects the code from type errors, even if a user attempts to enter invalid characters.

Tip: If you need to accept decimal numbers (e.g., price or weight), be sure to set the step="0.01" attribute (or another required step). By default, browsers often treat the step as 1, which may block the entry of decimal fractions or round them to the nearest integer when using arrows. To store such values in PHP, use the $input->getFloat() method instead of getInt().

Common Pitfalls

  • Strict Backend Typing: The HTML number field submits data as a string. If you use the 'string' or 'cmd' filter when retrieving the value via $input, you will get a string data type. This can lead to errors in mathematical operations (for example, "10" + "5" might work, but "10" * "2" requires explicit type casting). Always use the 'int' or 'float' filters (getInt()/getFloat() methods) to ensure a numeric type in PHP.
  • Input restriction applies only to spinner arrows: The min and max attributes restrict value selection via the interface arrows but do not prevent users from manually typing a number outside this range into the text field. The browser may show a warning upon form submission, but reliable boundary checks must always be duplicated on the server side (in PHP) before saving data.
  • Default Decimal Number Issue: If the step attribute is not specified, the browser defaults it to 1. This means the field will be considered "invalid" when entering decimal numbers (e.g., 1.5), and the arrows will only change the value by whole integers. To support decimal fractions, you must explicitly set step="any" or a specific step (e.g., step="0.01").
  • Locale Dependency: In some browsers, the display of the decimal separator (dot . or comma ,) depends on the user's language settings. However, the HTML5 standard requires that the field value always be sent to the server with a dot as the separator. If you use JavaScript to format the number according to the locale, ensure that the value is converted back to the standard dot-separated format before submitting the form; otherwise, PHP may not recognize it as a valid number.
0 items Cart
Consultation on the service:

You need a service to generate a file with XML fields for Joomla? Fill out the form below with information about the data you need and get a price for the finished file with Joomla XML fields