Zend Form: How to set the length of a text input or textarea element?

后端 未结 5 1883
悲&欢浪女
悲&欢浪女 2021-02-05 05:20

By default Zend Form Text elements don\'t have a width specified. Textarea elements have a default of rows="24" and cols="80". But

5条回答
  •  长发绾君心
    2021-02-05 05:57

    Generally it is good practice to add your form attributes in your fieldset class (or form class depending on how you have set it up).

    Here is an example:

    class SomeFieldSet extends Fieldset
    {
        /**
         * @var \Doctrine\Common\Persistence\ObjectManager
         * @access protected
         */
        protected $objectManager;
    
        /**
         * @param ObjectManager $objectManager
         * @param SomeEntity $claimPrototype
         * @param null $name
         * @param array $options
         */
        public function __construct(
            ObjectManager $objectManager,
            SomeEntity $somePrototype,
            $name = null,
            $options = array()
        ) {
            parent::__construct($name, $options);
    
            $this->objectManager = $objectManager;
    
            $this->setHydrator(new DoctrineObject($objectManager));
            $this->setObject($somePrototype);
    
        }
    
        public function init()
        {
    
            $this->add(
                [
                    'name'       => 'description',
                    'type'       => 'textarea',
                    'options'    => [
                        'label' => 'Some Label',
                        'instructions' => 'Some instruction',
                    ],
                    'attributes' => [
                        'class' => 'form-control',
                        'placeholder' => 'Some placeholder',
                        'required' => 'required',
                        'rows' => 10
                    ],
                ]
            );
    
    }
    

提交回复
热议问题