Reputation: 2390
I'm getting a bit confused with zf2 annotations, I created a few elements based on this tutorial:
/**
* @Annotation\Attributes({"type":"text" })
* @Annotation\Required(false)
* @Annotation\Options({"label":"Cardholder's Name: *:"})
*/
protected $cardholder;
For simple text all is working fine but I'm stuck when try to create a select element.
If you know any tutorial or github repo please let me know.
Upvotes: 4
Views: 4968
Reputation: 19
Try this:
/**
* @Annotation\Type("Zend\Form\Element\Select")
* @Annotation\Required(false)
* @Annotation\Options({"label":"Cardholder's Name: *:", "value_options":{"1":"VISA", "2":"MASTER CARD", "3":"AMERICAN EXPRESS"}})
*/
protected $cardholder;
Upvotes: 2
Reputation: 461
Try this
/**
* @Annotation\Type("Zend\Form\Element\Select")
* @Annotation\Required({"required":"false" })
* @Annotation\Filter({"name":"StringTrim"})
*
*
*/
Upvotes: 0
Reputation: 2390
Problem was in view
so to get select you need
added example for validation and filtering
/**
* @Annotation\Attributes({"type":"text" })
* @Annotation\Options({"label":"Cardholder's Name: *:"})
* @Annotation\Required(false)
* @Annotation\Filters({"name":"StripTags"},{"name":"StringTrim"}})
* @Annotation\Validator({"name":"StringLength","options":{"min":"1", "max":"20"}})
*/
protected $cardholder;
/**
* @Annotation\Type("Zend\Form\Element\Select")
* @Annotation\Options({"label":"Description"})
* @Annotation\Attributes({"options":{"1":"Visa","2":"Maestro"}})
*/
protected $cardType;
and in view
<dt><?php echo $this->formLabel($form->get('cardholder')); ?></dt>
<dd><?php
echo $this->formInput($form->get('cardholder'));
echo $this->formElementErrors($form->get('cardholder'));
?></dd>
<dt><?php echo $this->formLabel($form->get('cardType')); ?></dt>
<dd><?php
echo $this->formSelect($form->get('cardType'));
echo $this->formElementErrors($form->get('cardType'));
?></dd>
Upvotes: 8