Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Style form elements in Zend Framework

I have some Zend_Form

$text = new Zend_Form_Element_Textarea('text');
$text->setLabel('Leave a reply')
     ->setAttrib('rows', 9)
     ->setAttrib('cols', 50)
     ->addValidator('NotEmpty')
     ->setRequired(true)
     ->setAttrib('class', 'comment_form');

I wand to style this form, to add some style for label tag and another style for textarea tag. How can I do that?

like image 404
Pavlo Avatar asked Jan 21 '26 01:01

Pavlo


2 Answers

You need to modify the decorators directly:

$text->getDecorator('Label')->setOption('class', 'my-class-name');

Or you can style the element appropriately using the generated ID as suggested by Mark. As a general rule if it needs to apply to more than a single form id do it the way i suggest to minimize the css length and add some clarity.

like image 79
prodigitalson Avatar answered Jan 27 '26 00:01

prodigitalson


  $textarea = new Zend_Form_Element_Textarea ('intro', array(
  'label' => 'Introduction',
  'attribs' => array ('style' => 'width: 100px'),
  ));

or if you have already got an element in $textarea

$textarea->setAttrib('style', 'width: 100px;');
like image 40
2 revsSergey Toropenko Avatar answered Jan 27 '26 01:01

2 revsSergey Toropenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!