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.
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>
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;
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