We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Custom value of submit button generated by Phalcon\Forms\Element\Submit

Hi all! Maybe it's very simple question, but I can't find the answer. I have form class LoginForm with Submit button like LoginForm in Vokuro example.

$t - is an object with translations for preferred language. So I need something like that:

<input type="submit" class="red-button" value="Log In">

or

<input type="submit" class="red-button" value="Увійти">

depends on lanuage, but it always like this:

<input type="submit" class="red-button" value="login">

This is my code:

$submit = new Submit('login', array(
    'class' => 'red-button',
    'value' => $t->Form->Login->Submit // This won't work! =(
));
$submit->setDefault($t->Form->Login->Submit); // This won't work too! =(
$this->add($submit);

Also I tried this:

{{ form.render('login', ['value': t.Form.Login.Submit]) }}


98.9k

There is a bug in 1.1.0 related to this, it's fixed in 1.2.0 but this version is still alpha, you can use the element name with the translation:

$submit = new Submit(t.Form.Login.Submit)

Thank you for your answer! I made it by raw HTML.

From one of my projects:

<?php

namespace Library\Form\Element;

class Submit extends \Phalcon\Forms\Element\Submit
{

    public function __construct($name, $parameters = array())
    {
        parent::__construct($name, $parameters = array());
        $this->setAttribute('class', 'btn btn-primary"');
    }

    public function render($attributes = array())
    {
        $this->setName(
            \Phalcon\DI::getDefault()
            ->getTranslate()
            ->translate($this->getName())
        );
        return parent::render($attributes);
    }

}

and in the form:

# ...
        $this->add(
            new Submit('Login')
        );
# ...