Ver Mensaje Individual
  #5 (permalink)  
Antiguo 02/01/2014, 12:18
sintel_1
 
Fecha de Ingreso: enero-2014
Ubicación: Navarra
Mensajes: 94
Antigüedad: 10 años, 4 meses
Puntos: 18
Respuesta: Script: Formulario-estilo

Hola.

Efectivamente, el problema está en el "name" del checkbox

Puedes solucionando creando un array con name="marcado[]"
o poner un name diferente.

usando un array podría quedar así :

Código:
<html>
<head>
<title>Ejercicio_3</title>
</head>
<body>
<?php
if (isset($_REQUEST['aceptar']))
{
$marcado=$_REQUEST['marcado'];
$texto=$_REQUEST['texto'];
} else
{
$texto='Lorem Ipsum Dolor Sit Amet';
$marcado=$texto;
} 
$n = count($marcado);
$i = 0;
$estilo = "font-weight: normal; font-style: normal; text-decoration: none;";

while ($i < $n)
   {
       if ($marcado[$i] == "bold") { $estilo.=" font-weight: bold;"; $weight = "bold"; }
       if ($marcado[$i] == "italic") { $estilo.=" font-style: italic;"; $style = "italic"; }
       if ($marcado[$i] == "underline") { $estilo.=" text-decoration: underline;"; $decoration = "underline"; }
      $i++;
   }
 
 echo "<p style=\"$estilo\" >$texto</p>";

?>
<hr>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
Introduce el texto a mostrar:
<input type="text" name="texto" value="<?php echo $texto ?>">
<br>
Estilo del texto:
<input type="checkbox" name="marcado[]" value="bold" <?php if ($weight == "bold") echo 'checked' ?> > Negrita
<input type="checkbox" name="marcado[]" value="italic" <?php if ($style == "italic") echo 'checked' ?> > Cursiva
<input type="checkbox" name="marcado[]" value="underline" <?php if ($decoration == "underline") echo 'checked' ?> > Subrayado
<br>
<input type="submit" name="aceptar" value="Aceptar">
</form>
</body>
</html>
no lo he probado, pero deberia de funcionar.

saludos.