Reputation: 5084
public function init()
{
$txt = $this->createElement('text', '0')
->setBelongsTo('txt');
$this->addElement($txt);
$fields = $this->createElement('text', '0')
->setBelongsTo('fields');
$this->addElement($fields);
}
But in this case one of fields is not displayed. How to make both field's arrays start from 0.
I could leave txt[] and fields[] but when I do this->populate($_POST);
it doesn't work.
Upvotes: 0
Views: 345
Reputation: 40675
There is something wrong in general. The second parameter you pass to the element has to be its name, which has to be unique (form field name). The setBelongsTo
calls will not work because your elements do not have the respective names. What you are doing is to create an element with the name 0
and then overwrite it with another element, which is the one displayed. You will see this, if you look at your source code in the browser. If you're using setIsArray
then you should make both elements belong to the same array.
I don't know exactly what you want to achieve but it should look more like this:
public function init()
{
$txt = $this->createElement('text', 'mytext')
->setBelongsTo('myarray');
$this->addElement($txt);
$fields = $this->createElement('text', 'myothertext')
->setBelongsTo('myarray');
$this->addElement($fields);
}
Upvotes: 1