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

Form element value problem

I am using form classes and element classes to make forms in my project. For each element i extended the render method to display the below html:

<div class="form-group">
    <label>
        {{ field.getLabel() }}
        {% if field.getAttribute("_required") %}<span class="required">*</span>{% endif %}
    </label>
    <input type="number" name="{{ field.getName() }}" class="form-control {{ field.getAttribute("_cls") }}"
    value="{{ field.getValue() }}">
    <i class="fa fa-fw validation-icon"></i>
    <span class="help-block validation-msg"></span>
</div>

In the code snippet, field is a Forms\Element instance. When i have element names like "aName", the method getValue() works fine, but when the name is like "aName[foo]" Phalcon can't get the value for the field.

Any ideas ?

Use in Form:

class ContactForm extends Form
{
    public function initialize()
    {
        $this->add(new Text("name", [
            'name' => 'name[]'
        ]));
    }
}

and Volt:

{{ field.getAttribute ('name') }}