Hello, everyone!
In a controller I set up a label for a button as an empty string:
$form = new Form();
$submit = new Submit('submit', array('value' => 'Next'));
$submit->setLabel('');
getLabel()
returns an empty string which is expected by me:
$submit->getLabel() // returns an empty string
But label()
returns <label for="submit">submit</label>
which is unexpected by me:
$submit->label() // returns '<label for="submit">submit</label>'
Here is my In my .phtml file:
<form action="" method="POST">
<?php
foreach ($form as $element) {
$messages = $form->getMessagesFor($element->getName());
if (count($messages)) {
foreach ($messages as $message) {
?>
<div class="message"><?= $message ?></div>
<?php
}
}
echo $element->render();
echo $element->label();
}
?>
</form>
Here is the output: <input value="Next" type="submit" /><label for="submit">submit</label>
So, to prevent rendering the label with an empty text I added the extra condition:
echo $element->render();
if($element->getLabel() != '') {
echo $element->label();
}
I think $submit->label()
should return an empty label <label for="submit"></label>
(or an empty string?) instead of <label for="submit">submit</label>
. Does anybody agree?