We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

$element->setLabel() and css class

How do I add a css "class=whatever" to the Label?

In a Form class:

MyForm extends Form(
    public function initialize() {
        $email = new Text('email');
        // How do I add a css "class=whatever" to the above email label?



Hardcode like this

<form method="post">
        // Проходим через форму
        foreach ($form as $element) {

            // Собираем все сгенерированные сообщения для текущего элемента
            $messages = $form->getMessagesFor($element->getName());

            if (count($messages)) {
                // Выводим каждый элемент
                echo '<div class="messages">';
                foreach ($messages as $message) {
                    echo $message;
                echo '</div>';

            echo '<p>';
            echo '<label for="', $element->getName(), '">', $element->getLabel(), '</label>';
            echo $element;
            echo '</p>';

    <input type="submit" value="Send"/>

Or you can try to create own \Phalcon\Tag, pass it to Di and rewrite lable method maybe it can helps you


Yes, I know about this, thank you. I thought there is an array $option or something which I am missing, but seems not. Will make my own Tag then.


After checking the code, it actually can be done, pass the array with options to the label().

In Volt:

form.label('email', ['class': 'whatever']) 

or in PHP

$form->label('email', ['class' => 'whatever']);

Yeap, but we was talking about Form Elements as I known.