Here is the XML for a particular form field:
<field type="text" name="first-name" id="first-name" label="MOD_LABEL_FIRST_NAME"
required="required" maxlength="27" color="yellow" />
My problem is that when displaying the form as HTML, the attributes are being filtered in some way. For example, the attribute type
is displayed as part of the markup but attributes like required
and color
are not. (Color
is a dummy attribute I have created for testing purposes, but required
is important as I want to use the HTML5 required behaviour.)
Here is the markup output for the specific field described in the XML above:
<label id="first-name-label" for="first-name">First name</label>
<input type="text" name="first-name" id="first-name" maxlength="27"/>
I know custom attributes like color
exist as part of the object - here is the result from a var_dump of $oForm->getField('first-name')
:
object(JFormFieldText)#773 (19) {
["type":protected]=>
string(4) "Text"
["element":protected]=>
object(JXMLElement)#772 (1) {
["@attributes"]=>
array(9) {
["type"]=>
string(4) "text"
["name"]=>
string(15) "first-name"
["id"]=>
string(15) "first-name"
["label"]=>
string(30) "MOD_LABEL_FIRST_NAME"
["required"]=>
string(8) "required"
["maxlength"]=>
string(2) "27"
["color"]=>
string(6) "yellow"
}
}
Further, I have tried following the methods described in the answer to this question as they seemed relevant, but it hasn't worked in my case, as I just get syntax errors:
$oField = $oForm->getField('first-name');
echo $oField->type; // returns 'Text'
echo $oField->element->["color"]; // returns syntax error
While it would be interesting to know how to access/manipulate custom attributes in this case, my main question is why are only some attributes displayed in the markup?