How to add style to Zend Form Elements

For programming and general questions on Zend Framework
Post Reply
laurens_at_hol
Posts: 33
Joined: Wed Jun 03, 2009 7:50 am

How to add style to Zend Form Elements

Post by laurens_at_hol » Fri Jul 03, 2009 3:48 pm

Hi,

does someone know where to find some good and easy documentation about how to style zend form elements? I would like to style elements like Zend_Form_Element_Text, Zend_Form_Element_Textarea and Zend_Form_Element_Reset.

Thanks!

diogovn
Posts: 7
Joined: Wed Mar 18, 2009 4:18 pm

Re: How to add style to Zend Form Elements

Post by diogovn » Fri Jul 03, 2009 8:41 pm

Hmmm...isn't it just a matter of seeing how the final HTML for the form looks like and then making a CSS that style those elements?

dhaval4linux
Posts: 161
Joined: Fri May 22, 2009 2:35 pm

Re: How to add style to Zend Form Elements

Post by dhaval4linux » Mon Jul 06, 2009 6:49 am

Use Zend form decorator.
Using decorator you can place your element with different html tag.
Also you can apply style inlline or giving class to that element.
To apply class you need to do.

Code: Select all

$name = new Zend_From_Element_Text("txtName");
$name->class = "yourClassName";

To apply more attributes to your element use ->setAttribs() method

Code: Select all

$name = new Zend_From_Element_Text("txtName");
$name->setAttribs(array('style' => 'width:50px;', 'width' => '50'));
Best Regards,
Dhaval

abhaychaware
Posts: 37
Joined: Sun Jun 14, 2009 9:24 am

Re: How to add style to Zend Form Elements

Post by abhaychaware » Mon Jul 06, 2009 11:47 am

you could also define your classes in CSS and apply in zend form such as :

Code: Select all

$name = new Zend_From_Element_Text("txtName");
$name->setOptions(array('class'=>'css class name'));

dhaval4linux
Posts: 161
Joined: Fri May 22, 2009 2:35 pm

Re: How to add style to Zend Form Elements

Post by dhaval4linux » Tue Jul 07, 2009 1:19 pm

abhaychaware wrote:$name->setOptions(array('class'=>'css class name'));

Hey setOptions method is for other purpose, although it work same as setAttribs method.
Try to use setAttribs method.
Best Regards,
Dhaval

laurens_at_hol
Posts: 33
Joined: Wed Jun 03, 2009 7:50 am

Re: How to add style to Zend Form Elements

Post by laurens_at_hol » Thu Jul 16, 2009 10:33 am

Is there also a way to style the button of a Zend_Form_Element_File?

dhaval4linux
Posts: 161
Joined: Fri May 22, 2009 2:35 pm

Re: How to add style to Zend Form Elements

Post by dhaval4linux » Mon Jul 20, 2009 10:55 am

No its not possible either way, You can not style button of File element. accept border and height and width. but not in all browser..
Best Regards,
Dhaval

Post Reply