J'aimerai créer un combobox permettant de sélectionner une couleur et son code ... j'ai un début de code mais il ne reprend pas la sélection par défaut:
<?php
class Item{
var $_value = '';
var $_text = null;
var $_stylist = null;
function Item( $value, $text=null ){
$this->_value = $value;
$this->_text = $text;
}
function getValue(){
return $this->_value;
}
function setStylist( &$stylist ){
$this->_stylist =& $stylist;
}
function render(){
echo '<option value="' . htmlspecialchars( $this->getValue() ) . '"', $this->_stylize(), '>';
echo htmlspecialchars( !empty( $this->_text ) ? $this->_text : $this->getValue() );
echo '</option>';
}
function _stylize(){
if ( is_object( $this->_stylist ) ){
$this->_stylist->render( $this );
}
}
}
class Stylist{
var $_color = '';
function Stylist( $color ){
$this->_color = $color;
}
function render( &$item ){
echo ' style="color:' . htmlspecialchars( $this->_color ) . '; background-color:' . htmlspecialchars( $item->getValue() ) . '" ';
}
}
class Select{
var $_class = '';
var $_name = '';
var $_list = array();
function Select( &$list, $name='', $class=''){
$this->_class = $class;
$this->_name = $name;
$this->_list =& $list;
}
function render(){
echo '<select' . ( !empty( $this->_name ) ? ' name="' . htmlspecialchars( $this->_name ) . '"' : '' ) . ( !empty( $this->_class ) ? ' class="' . htmlspecialchars( $this->_class ) . '"' : '' ) .'>';
for ( $i=0, $n=count( $this->_list ); $i<$n; $i++ ){
$this->_list[ $i ]->render();
}
echo '</select>';
}
}
$stylist = new Stylist( 'white' );
$list = array();
$item = new Item( '#000000' );
$item->setStylist( $stylist );
$list[] = $item;
$item = new Item( '#336699' );
$item->setStylist( $stylist );
$list[] = $item;
$item = new Item( '#CC6600' );
$item->setStylist( $stylist );
$list[] = $item;
$lists['c_banniere'] = new Select( $list, 'color', 'inputbox' );
$lists['c_banniere']->render()
La selection par défaut est par exemple <?php echo $class_Config['c_banniere'];?>Quelqu'un serait-il en meusure de modofier le code pour que la saisis par défaut soit possible ?
Merci