Patch for <label> in HTML_QuickForm

From: Date: Sat, 12 Mar 2005 00:55:14 +0000
Subject: Patch for <label> in HTML_QuickForm
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-36659@lists.php.net to get a copy of this message
I've begun to use HTML_QuickForm and it's very handy. I'm just using the Default renderer at this point. I noticed the omission of the <label> tag around the {label} string. Specifying <label> lets the browser know that the string is a label and lets it do some extra stuff. For example, recent browsers will focus on the input element when you click on its label. Here are some patches for HTML_QuickForm to include the <label> tag. They're against version 3.2.4pl1. This first one makes sure that every element has a unique id in the DOM. This is in the constructor of HTML_QuickForm_element so the same call in the HTML_QuickForm_radio and HTML_QuickForm_checkbox constructors can be removed. $ diff element.php my-element.php 91a92
        $this->_generateId();
This other part updates the Default renderer. It makes the template include the <label for="elementid"> wrapper around the element label. It also adds code to renderElement() to replace the {id} in the template with the element's id attribute. $ diff Default.php my-Default.php 54c54
<         "\n\t<tr>\n\t\t<td align=\"right\" valign=\"top\"><!-- BEGIN required --><span style=\"color: #ff0000\">*</span><!-- END required --><b>{label}</b></td>\n\t\t<td valign=\"top\" align=\"left\"><!-- BEGIN error --><span style=\"color: #ff0000\">{error}</span><br /><!-- END error -->\t{element}</td>\n\t</tr>";
---
        "\n\t<tr>\n\t\t<td align=\"right\" valign=\"top\"><!-- BEGIN required --><span style=\"color: #ff0000\">*</span><!-- END required --><b><label for=\"{id}\">{label}</label></b></td>\n\t\t<td valign=\"top\" align=\"left\"><!-- BEGIN error --><span style=\"color: #ff0000\">{error}</span><br /><!-- END error -->\t{element}</td>\n\t</tr>";
281a282
            $html = str_replace('{id}', $element->getAttribute('id'), $html);
285a287
            $html = str_replace('{id}', $element->getAttribute('id'), $html);
I've tested this in my use and it works as advertised. I don't use QuickForm very extensively so it may break some cases that I don't have in my code. I trust the package maintainers will know if this might break anything. Thanks for QuickForm. I hope you can use these patches in the main distribution. -Turadg

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