I am trying to add a selectbox to one of my forms (which just with input type="text" elements are working pretty good) but all I get is just an empty selectbox with none tags in it. So this is the code I use:
Bla.php :: Bla->getInputFilter()
$inputFilter->add($factory->createInput(array(
'type' => 'Zend\InputFilter\Select',
'name' => 'payment_type',
'required' => true,
'filters' => array(
array('name' => 'Int'),
),
)));
BlaForm.php :: BlaForm->__construct():
$this->add(array(
'type' => 'Zend\Form\Element\Select',
'name' => 'payment_type',
'options' => array(
'label' => 'Payment',
'value_options' => array(
0 => 'Nur Überweisung',
1 => 'Nur Paypal',
2 => 'Nur Barzahlung im Voraus',
),
),
'attributes' => array(
'value' => 0 //set selected to "Nur Überweisung"
)
));
bla.php (View)
<div class="control-group">
<?php
echo $this->formLabel($form->get('payment_type')->setLabelAttributes(array(
'class' => 'control-label'
)));
?>
<div class="controls">
<?=$this->formElement($form->get('payment_type'));?>
<span class="help-inline"><?=$this->formElementErrors($form->get('payment_type'));?></span>
</div>
</div>
I already tried using "options" instead of "value_options" and yesterday I learned that it is just an alias of "value_options". Also I tried formSelect() instead of formElement() in my view but that doesn't change anything either. I even removed the umlauts from the strings for testing purposes...
Did anybody experience the same problem or has any idea, what I am currently doing wrong?
I just tried your examples locally against current master (rev 9747bd01d), and they worked without issue -- using either formCollection() on the form, or formElement() or formSelect() on the individual element. In each case, I get the following markup:
<select name="payment_type"><option value="0" selected="selected">Nur Überweisung</option>
<option value="1">Nur Paypal</option>
<option value="2">Nur Barzahlung im Voraus</option></select>
What version of ZF2 are you using? Can you test against either 2.0.2 or current master, please?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With