'Set maximum length for field in joomla
I want to set max length from default.php. Here is my XML format,
<fieldset name="sender_details">
<field name="sendername"
type="text"
label="SENDERV_SENDER"
description="SENDERV_SENDER_DESC"
default=""
required="true" />
</fieldset>
Here is the coding for default.php.
foreach ($this->form->getFieldset('sender_details') as $field) :
echo $field->label;
echo $field->input;
}
I had a variable $length=5.The text box should allow only 5 characters.The length is coming from the configuration. I need to do in default.php
kindly Help Me.
Solution 1:[1]
To specify max length in Joomla Text Field Like This
<fieldset name="sender_details">
<field name="sendername"
type="text"
label="SENDERV_SENDER"
description="SENDERV_SENDER_DESC"
default=""
maxlength="5"
required="true" />
</fieldset>
if you want your custom attribute then you can create joomla new field type or you can modify joomla form fields
libraries/joomla/form/fields/text.php
libraries/joomla/form/fields/textarea.php
libraries/joomla/form/fields/.......
any problem implementing please reply
Solution 2:[2]
The problem with editing core-files (libraries/joomla/form/fields/text.php, libraries/joomla/form/fields/textarea.php, libraries/joomla/form/fields/...) is, that with the next joomla-update these changes could be overwriten again.
Until joomla does noch correct this bug, is there any possibility to set a custom html-attribute to a jformfield before it renders with "print $field->input;" ?
edit: There already exists a bug-entry for that: http://issues.joomla.org/tracker/joomla-cms/3510?lang=de-DE
Solution 3:[3]
You can set in edit layout like this :
<?php echo $this->form->getInput('fieldname','maxLength',4); ?>
And then your html code is :
<input type="text" name="jform[fieldname]" id="jform_fieldname" maxlength="4">
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | biswarupadhikari |
| Solution 2 | Robert |
| Solution 3 | Alireza Balvardi |
