Html::showColorField PHP Method

showColorField() static public method

Display Color field
static public showColorField ( $name, $options = [] )
$name name of the element
$options array of possible options: - value : default value to display (default '') - display : boolean display or get string (default true) - rand : specific random value (default generated one)
    static function showColorField($name, $options = array())
    {
        $p['value'] = '';
        $p['rand'] = mt_rand();
        $p['display'] = true;
        foreach ($options as $key => $val) {
            if (isset($p[$key])) {
                $p[$key] = $val;
            }
        }
        $field_id = Html::cleanId("color_" . $name . $p['rand']);
        $output = "<input type='text' id='{$field_id}' name='{$name}' value='" . $p['value'] . "'>";
        $js = "\$('#{$field_id}').spectrum({preferredFormat: 'hex'});";
        $output .= Html::scriptBlock($js);
        if ($p['display']) {
            echo $output;
            return $p['rand'];
        }
        return $output;
    }

Usage Example

 public function showForm($ID, $options = array())
 {
     if (!$this->isNewID($ID)) {
         $this->check($ID, READ);
     } else {
         $this->check(-1, UPDATE);
     }
     $options['colspan'] = 2;
     $options['target'] = Toolbox::getItemTypeFormURL(__CLASS__);
     $this->showFormHeader($options);
     echo '<table class="tab_cadre_fixe">';
     echo "<tr class='line0'><td>" . __('Name') . " <span class='red'>*</span></td>";
     echo "<td>";
     //Html::autocompletionTextField($this, "name");
     echo '<input type="text" name="name" value="' . $this->fields['name'] . '" size="40" required>';
     echo "</td>";
     echo "</tr>";
     echo "<tr class='line1'><td>" . __('Description') . "</td>";
     echo "<td>";
     echo "<textarea name='comment' id ='comment' cols='45' rows='2'>" . $this->fields['comment'] . "</textarea>";
     //Html::initEditorSystem('comment');
     echo "</td>";
     echo "</tr>";
     echo "<tr class='line1'><td>" . __('HTML color', 'tag') . "</td>";
     echo "<td>";
     Html::showColorField('color', array('value' => $this->fields['color']));
     echo "</td>";
     echo "</tr>";
     $this->showFormButtons($options);
     return true;
 }
All Usage Examples Of Html::showColorField
Html