Я пытаюсь создать, коллекция HTML для цветов поля ввода .. который будет динамически добавляемая с помощью JavaScriptZF2, Форма коллекция не создающая правильное имя входа в ZF2
Моего ColorFieldset
кода
namespace Dashboard\Form;
use Zend\Form\Fieldset;
use Zend\InputFilter\InputFilterProviderInterface;
class ColorFieldset extends Fieldset implements InputFilterProviderInterface
{
public function __construct()
{
parent::__construct('color');
$this->add(array(
'name' => 'hash',
'options' => array(
'label' => 'Color'
),
'attributes' => array(
'required' => 'required',
'class' => 'input-mini'
)
));
}
/**
* @return array
\*/
public function getInputFilterSpecification()
{
return array(
'hash' => array(
'required' => true,
)
);
}
}
и добавил она в виде
$this->add(array(
'type' => 'Zend\Form\Element\Collection',
'name' => 'colors',
'options' => array(
'count' => 2 ,
'should_create_template' => true,
'allow_add' => true,
'target_element' => array(
'type' => 'Dashboard\Form\ColorFieldset'
)
)
));
и в моем файле просмотра .. colors.phtml
<div id="colors_container" class="">
<?php echo $this->formCollection($form->get('colors')); ?>
</div>
его вывода на печать, как
<div class="" id="colors_container">
<label><span>Color</span><input type="text" value="" class="input-mini" required="required" name="hash"></label>
<label><span>Color</span><input type="text" value="" class="input-mini" required="required" name="hash"></label>
<span data-template='<label><span>Color</span><input name="hash" required="required" class="input-mini" type="text" value=""></label>'></span>
</div>
Он должен печатать как .. который объяснил в zf2 manual 2.0
<div class="" id="colors_container">
<label><span>Color</span><input type="text" value="" class="input-mini" required="required" name="colors[0][hash]"></label>
<label><span>Color</span><input type="text" value="" class="input-mini" required="required" name="colors[1][hash]"></label>
<span data-template='<label><span>Color</span><input name="colors[__index__][hash]" required="required" class="input-mini" type="text" value=""></label>'></span>
</div>
Я ожидал имя HTML ввода в colors[__index__][hash]
. Но он печатает имя как <input type="text" value="" class="input-mini" required="required" name="hash">
.
В приведенном выше случае. Я получаю только одно имя цвета в сообщении $_POST['hash']
.
Почему zf2 не печатает <input type="text" value="" class="input-mini" required="required" name="colors[0][hash]">
? Пожалуйста, советьте, что не так в моем коде.
хороший вопрос ... thank u –