Re: HTML_QuickForm improvement suggestion

From: Date: Thu, 06 Mar 2003 11:30:19 +0000
Subject: Re: HTML_QuickForm improvement suggestion
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-14106@lists.php.net to get a copy of this message
May be it would be better to update HTML_Common class to add 'generateAutoID' (or something like this) method to it? Alexander Radivanovich wrote:
I discovered that checkbox and radiobutton elements don't use <label> html element to display text associated with them. I suggest the following code to fix this: For the HTML_QuickForm_checkbox element: function HTML_QuickForm_checkbox::toHtml() {
    static $autoid = 1;
    if (!($id = $this->getAttribute('id'))) {
            $id = '__cb' . $autoid++;
            $this->updateAttributes(array('id' => $id));
    }
    require_once('HTML/QuickForm/label.php');
    $label = new HTML_QuickForm_label($this, $this->_text);
    return parent::toHtml() . $label->toHtml();
} For the HTML_QuickForm_radio element: function HTML_QuickForm_radio::toHtml() {
    static $autoid = 1;
    if (!($id = $this->getAttribute('id'))) {
            $id = '__rb' . $autoid++;
            $this->updateAttributes(array('id' => $id));
    }
    require_once('HTML/QuickForm/label.php');
    $label = new HTML_QuickForm_label($this, $this->_text);
    return parent::toHtml() . $label->toHtml();
} The code gives auto-generated ids for the elements if default ones aren't specified. It will produce <input name="ichkTest" type="checkbox" value="1" id="__cb1" /><label for="__cb1">Check the box</label> for checkbox elements and <input name="iradTest" type="radio" value="1" id="__rb1" /><label for="__rb1">Check the radio button #1</label> for radiobutton elements.


« previous php.pear.dev (#14106) next »