HTML_QuickForm improvement suggestion
| From: | Alexander Radivanovich | Date: | Thu, 06 Mar 2003 11:25:05 +0000 |
| Subject: | HTML_QuickForm improvement suggestion | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-14105@lists.php.net to get a copy of this message | ||
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.
HTML_QuickForm_label class is in the attachment.
PS
What is the 'label' property in the 'HTML_QuickForm_element' class for?
I've found 'getLabel()', 'setLabel' methods there, but it seems like
they aren't used at all...