1
Bluenoser
XoopsFormSelect formatting data
  • 2013/4/27 3:20

  • Bluenoser

  • Just popping in

  • Posts: 24

  • Since: 2007/6/5 1


I am trying to add additional information to the XoopsFormSelect. I am trying to add information to the value to colour each drop down element. Here is my code.

class GAFormSelecttee_names extends XoopsFormSelect {
      function 
GAFormSelecttee_names($caption$name$value=nullsize=1$nullopt=false$otheropt=false) {
         
$db =& Database::getInstance();
         
$this->XoopsFormSelect($caption$name$value$size);
         if (
$nullopt)
             
$this->addOption('','-');
         
$sql "SELECT tee_name_id, name, fgcolour, bgcolour FROM ".$db->prefix("ga_tee_names")." ORDER BY name";
         
$result $db->query($sql);
         while (
$myrow $db->fetchArray($result)) {
           
$this->addOption($myrow['tee_name_id'].'" style="background-color:'.$myrow['bgcolour'].';color:'.$myrow['fgcolour'].';',$myrow['name']);
         }
      }
 }


The problem is that my " get converted to the HTML equiv of "

Anyway I can prevent this?

2
irmtfan
Re: XoopsFormSelect formatting data
  • 2013/4/27 11:04

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


you should just change the render function and add some functionality . just one line is enough
eg: like this:
xoops_load('XoopsFormSelect');
class 
MyModuleFormSelect extends XoopsFormSelect
{
   function 
render()
    {
        
$ele_name $this->getName();
        
$ele_title $this->getTitle();
        
$ele_value $this->getValue();
        
$ele_options $this->getOptions();
        
$ret '<select size="' $this->getSize() . '"' $this->getExtra();
        if (
$this->isMultiple() != false) {
            
$ret .= ' name="' $ele_name '[]" id="' $ele_name '" title="'$ele_title'" multiple="multiple">' ;
        } else {
            
$ret .= ' name="' $ele_name '" id="' $ele_name '" title="'$ele_title'">' ;
        }
        foreach(
$ele_options as $value => $name) {
            
$ret .= '<option value="' htmlspecialchars($valueENT_QUOTES) . '"';
            
$ret .= ' id="' $value '"'// add just this irmtfan
            
if (count($ele_value) > && in_array($value$ele_value)) {
                
$ret .= ' selected="selected"';
            }
            
$ret .= '>' $name '</option>' ;
        }
        
$ret .= '</select>';
        return 
$ret;
    }
}

Also I think you should change your mind a little.
I think it would be better to use only css and not store colors in database.
anyway the above could be used like this:
#ele_name option#value {
background-color:RED;
}

you can use css or database. what you like.

Login

Who's Online

261 user(s) are online (171 user(s) are browsing Support Forums)


Members: 0


Guests: 261


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