Haven't converted to J4 yet because of an extension dependency, but wanted to report this in case it was still an issue.
getLabel in note.php field last line is
return '</div><div ' . $class . '>' . implode('', $html);
should be
return '<div ' . $class . '>' . implode('', $html) . '</div>';
Use the note type in any form in an admin extension. The incorrect </div>
will close
the main container.
Labels |
Removed:
?
|
Labels |
Added:
No Code Attached Yet
|
Thank you for pointing this out. I would appreciate your updating it, as I'm not completely clear on how to escape it properly.
Got it. Thanks muchly.
This issue seems to be Joomla 3. I have tested with Joomla 4. But in Joomla 4 it's the same PHP code and no invalid HTML:
return '</div><div ' . $class . '>' . implode('', $html);
I may not have explained it well. The generated HTML is perfectly valid, but it does the wrong thing. The </div>
closes an outer div and the <div>
starts a new div at the same level as the outer div. What it should do is return a div with the label code in it and close it.
If this isn't clear, I can code an example.
I would say that's on purpose. Because in note fields the label is just a H4 headline and not a real field label. The same for the description.
Yes, the empty divs are not nice in Joomla 3 but I think it would be bigger effort to put the label (= headline) into a div with class="control-label"
than to leave it as it is because you have to change CSS, too, or things like that.
As always: I don't have to decide that. But that's for sure not a security issue (or a bug). Joomla 3 is locked for other fixes than these.
Examples from Joomla 3.10.11:
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-11-03 02:40:04 |
Closed_By | ⇒ | jjbongio |
I'm not sure I'm describing this correctly (I'm new to the forum, so be patient).
I have a field defined in a form as
<field
name="note1"
type="note"
label="Some Label"
/>
When I use this form in the backend, the returned label is
</div><h4>Some Label<div>
which closes out the containing div.
Status | Closed | ⇒ | New |
Closed_Date | 2022-11-03 02:40:04 | ⇒ | |
Closed_By | jjbongio | ⇒ |
@jjbongio you described it correctly.
This </div><h4>Some Label<div>
is on purpose.
Look the layout file joomla.form.renderfield, it render field label and input, like:
<div class="control-group">
<div class="control-label"><?php echo $label; ?></div>
<div class="controls"><?php echo $input; ?></div>
</div>
Now, because we do not want that Note label be inside <div class="control-label">
, we do return '</div><div ' . $class . '>' . implode('', $html);
in the Note field label, and in result we get:
<div class="control-group">
<div class="control-label">
</div><h4>Some Label</h4><div>
</div>
<div class="controls"><?php echo $input; ?></div>
</div>
As you can see result markup is correct, even when $field->label
return incorect one.
When I use this form in the backend, the returned label is
You probably use it as echo $field->label
, try use it as echo $form->renderField($field)
.
Or add extra wrapper for a Note field on your own: echo '<div>' . $field->label . '</div>'
;
In this case your form will not be broken.
@jjbongio I have marked your code so that it is visible. I am wondering how you check the source code of your site?
I have added your code in user config.xml and get this:
If your structure is destroyed then the error could be somewhere on your site and produce a side effect here.
I am wondering how you check the source code of your site?
The Inspector not a reliable source, it shows rendered result (by browser) not real markup (from server).
Because Browser may magicaly fix a broken markup, it will looks correct in the Inspector.
And it possible to get a broken markup with Note field. Check my previus comment for details.
When rendering on your own (I mean without use of $form->renderField($field)
), example:
<p><?php echo $field->label; ?></p>
It will produce:
<p></div><h4>Some Label</h4><div></p>
It does not happens in core forms, but easily in 3rd extensions in custom form.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-11-04 01:21:20 |
Closed_By | ⇒ | jjbongio |
I was looping through $form->getFieldSet() as $field and echoing $field->label and then $field->input
When I changed it to echo $field->renderField (), it worked nicely without closing the parent div.
Thanks to all for your comments.
Spam with external link faking a Joomla site removed.
@jjbongio If you check the description of your issue on GitHub you will see that the markup is not visible, e.g. the
<div>
. Markup or code needs to be quoted with ` to be visible here. I could correct that for you, but I thought it's better if I let you know first. Let me know if you have some questions or if I shall change the description for you.