Powered by Ajaxy
Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

PHP: Création automatique d’un menu ‘select’ HTML


{filelink=12503}

<?php
 
function input_select($nom_control, $selected, $options, $multiple = false)
{
    print '
<select name="' . $nom_control;
    // Pour les sélections multiples
    if ($multiple) { print '[]" multiple="multiple'; }
    print '">';
 
    $selected_options = $options;
    if ($multiple) {
        foreach ($selected[$nom_control] as $val) {
            $selected_options[$val] = true;
        }
    }
    else
    {
        $selected_options[ $selected[$nom_control] ] = true;
    }
 
    foreach ($options as $option => $label) {
        print '
<option value="' . htmlentities($option) . '"';
        if ($selected_options[$option])
        {
            print ' selected="selected"';
        }
        print '>' . htmlentities($label) . '</option>
 
';
    }
    print '</select>
 
';
}
 
$pays=array('Paris','Londre','New York','madrid');
$nom_select='pays';
$elem_select=1;
input_select($nom_select,$elem_select,$pays,true);
 
?>

No comments yet.

Leave a Comment