Ticket #123 (new defect)

Opened 9 months ago

Solar_View_Helper_Form is always rendering the label tag

Reported by: Benjamin Kaineder/PACE Owned by: pmjones
Priority: minor Component: code
Keywords: form helper Cc:

Description

Problem

Upon calling fetch(), a label tag is rendered for every element even if there was no label property specified when creating the element. This especially is a disturbance with buttons (which may not need a label) and xhtml elements, because it may mess up the layout (depending on the css).

Steps to reproduce

This is an example controller action:

public function actionTest() {
    $this->formanm = Solar::factory('Solar_Form');
    $this->formanm->setElements(
        array(
            'surname' => array(
                'type'  => 'text',
                'label' => 'Surname, Forename',
            ),
            'forename' => array(
                'type'  => 'text',
            ),
            'process' => array(
                'type'  => 'submit',
                'value' => 'Register',
            ),
        ));

Proposed solution

in Solar/View/Helper/Form.php, change line 733 from

$form[] = "            <dt$require><label$require for=\"$id\">$label</label>$dt_descr</dt>";

to

if (strlen($label) > 0) {
    $form[] = "            <dt$require><label$require for=\"$id\">$label</label>$dt_descr</dt>";
}

And line 751 from

$form[] = "            <dt><label>$label</label></dt>";

else

if (strlen($label) > 0) {
    $form[] = "            <dt><label>$label</label></dt>";
}

Remark: Maybe it would be cleaner to check against null (thus allowing an empty label if the user wants it that way), but this would require more changes (line 654, and the content of $infolabel?)

Attachments

Add/Change #123 (Solar_View_Helper_Form is always rendering the label tag)

Author



Action
as new
 
Note: See TracTickets for help on using tickets.