Pear QuickForms -- How do I integrate CSS?

Posted on 2008-11-05
Last Modified: 2012-05-05
I'm working my way through PEAR and using the QuickForms.  I have only been working with PEAR for a few days now.

How can I change element classes?  All the elements are labeled 'class="element"'.  What if I want 'class="address"'?

Also, is there a way to stick in a div or span tag?

It would seem there has to be a way to integrate CSS style sheets, but I can't find it.

I've attached the code I'm working with.  I want to be able to make the address textarea separate from the rest of the elements so I can position it to the right of the name, phone, email fields.


require_once 'HTML/Page2.php';

require_once 'HTML/QuickForm.php';

require_once 'HTML/QuickForm/Renderer/Tableless.php';

$page = new HTML_Page2();

$page->setTitle('Personal Information Form');


div.table {

    border: 1px solid #000;


li { 

display: inline;



$renderer =& new HTML_QuickForm_Renderer_Tableless();

$form =& new HTML_QuickForm('PersonalInfo');

$form->addElement('header', null, 'Personal Information Form');

$intro = "Hi, this is the intro.<p>";

$form->addElement('static', '', '', $intro);

$form->addElement('text', 'name', 'Name', array('size' => 50, 'maxlength' => 255));

$form->addElement('text', 'phone', 'Phone', array('size' => 50, 'maxlength' => 255));

$form->addElement('text', 'email', 'Email', array('size' => 50, 'maxlength' => 255));

$form->addElement('textarea', 'address', 'Address', array('wrap' => 'virtual', 'rows' => 8, 'cols' => 50));

if ($form->validate())






$htmlout = $renderer->toHtml();




Open in new window

Question by:ibanja
    LVL 50

    Expert Comment

    by:Steve Bink
    Try something like this:

    $form->addElement('textarea', 'address', 'Address', array('wrap' => 'virtual', 'rows' => 8, 'cols' => 50, 'class' => 'address'));

    Open in new window


    Author Comment

    Thanks routinet,

    I've tried that.  I should have been more clear... I wanted to have more control over the "li" or "label" tags that are generated.  Also, i wanted to add div and span tags.

    LVL 50

    Accepted Solution

    The API documentation does not appear to support that depth of control.  To move forward with this, you'll be digging into the class code for QuickForms and the Renderer.  You could certainly extend the code to do exactly what you want, but this will not be a quick fix.

    Author Comment


    Yep, I think I'm going to write my own class, or possibly extend existing classes.

    Thanks for the help.  


    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to dynamically set the form action using jQuery.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now