Ver Mensaje Individual
  #3 (permalink)  
Antiguo 03/12/2007, 09:48
Sanubrio
 
Fecha de Ingreso: septiembre-2007
Mensajes: 220
Antigüedad: 17 años, 4 meses
Puntos: 1
Re: POST: problema al enviar el valor de un combo

Código PHP:
$options = array(
  
=> 'Gato',
  
=> 'Perro',
  
=> 'Puma'
);

$selected_id = (isset($_POST['animal']) && isset($options[$_POST['animal']])) ? $_POST['animal'] : 2;

echo 
'<form method="post">';
echo 
'<select name="animal">';
foreach (
$options as $id => $nombre)
{
    echo 
'<option value="'.$id.'"'.($id == $selected_id ' selected="selected"' '').'>'.$nombre.'</option>';
}
echo 
'</select>';
echo 
'<br />';
echo 
'<input type="submit" />';
echo 
'</form>'