1
Dave_L
XoopsFormText "size" parameter
  • 2006/12/28 21:29

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


I normally use Smarty templates for forms, in conjunction with the XoopsForm classes. This allows more flexibility in the layout.

One issue is a minor annoyance.

CSS attributes don't fully control the display of form elements, such as textboxes. The textbox's "size" attribute seems to determine how wide the box will be, regardless of the CSS attributes such as "width".

I'd like to specify the "size" value in the template, rather than in the .php script that calls the XoopsForm class methods, to keep all the display settings in one place.

But I haven't found a way of doing this.

Has anyone else encountered this problem and found a solution?

2
irmtfan
Re: XoopsFormText "size" parameter
  • 2006/12/29 4:56

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


UP
i want it too if its possible!
but i dont see any module do it without php.

3
frankblack
Re: XoopsFormText "size" parameter
  • 2006/12/29 11:02

  • frankblack

  • Just can't stay away

  • Posts: 830

  • Since: 2005/6/13


All you need is the id of that input field. If the id is missing just add it.

This one is for "Edit account" "Real name":
input#name { background-color:pink; width: 400px;}

4
Dave_L
Re: XoopsFormText "size" parameter
  • 2006/12/29 22:39

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


Thanks, that worked.

5
Dave_L
Re: XoopsFormText "size" parameter
  • 2006/12/30 17:37

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


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'025false"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>

6
irmtfan
Re: XoopsFormText "size" parameter
  • 2006/12/30 19:44

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


Yes Thank you both!
and i think module developers can use the method.
more css base modules needed.

Login

Who's Online

239 user(s) are online (141 user(s) are browsing Support Forums)


Members: 0


Guests: 239


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Apr 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits