5
I realized the problem I previously had was due to my associating CSS attributes with the table cell containing the input tag, rather than with the input tag itself.
In this particular application, I'm generating a bunch of input tags in a table. The "id" approach works, but is cumbersome because it requires a lot of CSS definitions.
But I found a better approach. By extending the form class, I can prove a "class" attribute when I create the form element:
/**
* Extension to XoopsThemeForm class that allows extra attributes to be passed to addElement method.
*/
require_once XOOPS_ROOT_PATH . '/class/xoopsform/themeform.php';
class XoopsThemeFormExtra extends XoopsThemeForm
{
/**
* Add an element to the form
*
* @param object &$formElement reference to a {@link XoopsFormElement}
* @param bool $required is this a "required" element?
* @param string $extra Extra attributes.
*/
function addElement(&$formElement, $required = false, $extra = '')
{
if (!empty($extra)) {
$formElement->setExtra($extra);
}
parent::addElement($formElement, $required);
}
} // class XoopsThemeFormExtra
Example of creating an element:
...
$form = new XoopsThemeFormExtra('The Form', 'form1', 'edit.php', 'post', true);
$form->addElement(new XoopsFormText('Username', 'uname', 0, 25, false, "class='uname'");
...
And in the template:
<style>
input.uname {width:12em;}
style>
...
<td><{$form1.elements.uname.body}>td>
...
Compiled HTML:
<td><input type='text' name='uname' id='uname' size='0' maxlength='20' value='' class='uname' />td>