Foros del Web » Programando para Internet » PHP »

Checkbox que se borran

Estas en el tema de Checkbox que se borran en el foro de PHP en Foros del Web. Buenas, hice una pregunta un par de días a la comunidad para una duda sobre una pagina de futbol, en la que estoy trabajando. Pero ...
  #1 (permalink)  
Antiguo 05/11/2010, 07:19
 
Fecha de Ingreso: noviembre-2010
Mensajes: 4
Antigüedad: 13 años, 5 meses
Puntos: 0
Checkbox que se borran

Buenas, hice una pregunta un par de días a la comunidad para una duda sobre una pagina de futbol, en la que estoy trabajando. Pero he seguido trabajando, y en la parte donde cada jugador entra y hace click en cada checkbox para decir si viene o no, luego al refrescar la página o entra otra persona se borra, por lo que es muy difícil saber quien viene y quien no.

Os pongo el codigo de la página:

Código:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>

<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
		<title>Olivereta United.tk</title>
		<link href="style.css" rel="stylesheet" type="text/css" media="all"/>
	</head>



<body>
	<div id="container">

		<div id="main-title"><span style="font-weight: 400"><font face="Arial Black" style="font-size: 9"><span style="font-weight: 400">Olivereta United</span></font></span></div>
		<div id="header-image"></div>
		<div id="navbar">

			<font face="Arial Black" style="font-size: 9">

			<a href="Equipo.html"><span style="font-weight: 400">Equipo</span></a><span style="font-weight: 400"> ||
			</span>
		<a href="Contacto.html"><span style="font-weight: 400">Contacto</span></a><span style="font-weight: 400"> ||
			</span>
		<a href="Proximo partido.html"><span style="font-weight: 400">Próximo partido</span></a></font></div>
    <div id="body">
     <?php
     if (isset($_POST['expediente']))
     {
         foreach ($_POST['expediente'] as $expediente_s)
             $seleccionado[$expediente_s] = "checked='checked'";
     }
 		?>
			<h1><font face="Arial">Viernes, 05/11/2010</font></h1>
			<form id="form1" action="mantener_checkbox.php" method="post">
			<div id="main-text">
            <title></title>
            <title></title>
            <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
			<link href="Proximo partido.html" rel="stylesheet" type="text/css">

              <p class="byline">&nbsp;</p>
              <p>&nbsp;</p>
            <table width="400" border="0" align="center">
              <tr>
                <td width="200" rowspan="2" align="center" bgcolor="#999999">Jugadores</td>
                <td colspan="2" align="center" bgcolor="#999999">Asistencia</td>
              </tr>
              <tr>
                <td width="100" align="center" bgcolor="#999999">Si</td>
                <td width="100" align="center" bgcolor="#999999">No</td>
              </tr>
              <tr>
                <td width="200" align="center">Marcos</td>
                <td align="center"><input type="checkbox" onclick="if(this.checked) this.form.submit();" name="expediente[]" <?php echo $seleccionado['1'] ?> value="1" /></td>
                <td align="center"><input type="checkbox" name="expediente[]" <?php echo $seleccionado['2'] ?> value="2" />
                  <br /></td>
              </tr>
              <tr>
                <td width="200" align="center" bgcolor="#CCCCCC">Jose Miguel</td>
                <td align="center" bgcolor="#CCCCCC"><input type="checkbox" name="expediente[]" <?php echo $seleccionado['3'] ?> value="3" />
                  <br /></td>
                <td align="center" bgcolor="#CCCCCC"><input type="checkbox" name="expediente[]" <?php echo $seleccionado['4'] ?> value="4" />
                  <br /></td>
              </tr>
              <tr>
                <td width="200" align="center">Joaquin</td>
                <td align="center"><input type="checkbox" name="expediente[]" <?php echo $seleccionado['5'] ?> value="5" />
                  <br /></td>
                <td align="center"><input type="checkbox" name="checkbox6" id="checkbox6" /></td>
              </tr>
              <tr bgcolor="#CCCCCC">
                <td width="200" align="center">Alejandro</td>
                <td align="center"><input type="checkbox" name="checkbox4" id="checkbox4" /></td>
                <td align="center"><input type="checkbox" name="checkbox3" id="checkbox3" /></td>
              </tr>
              <tr>
                <td width="200" align="center">Alberto</td>
                <td align="center"><input type="checkbox" name="checkbox" id="checkbox" /></td>
                <td align="center"><input type="checkbox" name="checkbox2" id="checkbox2" /></td>
              </tr>
              <tr bgcolor="#CCCCCC">
                <td width="200" align="center">Guillermo</td>
                <td align="center"><input type="checkbox" name="checkbox4" id="checkbox4" /></td>
                <td align="center"><input type="checkbox" name="checkbox3" id="checkbox3" /></td>
              </tr>
              <tr>
                <td width="200" align="center">Nacho</td>
                <td align="center"><input type="checkbox" name="checkbox" id="checkbox" /></td>
                <td align="center"><input type="checkbox" name="checkbox2" id="checkbox2" /></td>
              </tr>
              <tr bgcolor="#CCCCCC">
                <td width="200" align="center">Carlos</td>
                <td align="center"><input type="checkbox" name="checkbox4" id="checkbox4" /></td>
                <td align="center"><input type="checkbox" name="checkbox3" id="checkbox3" /></td>
              </tr>
              <tr>
                <td width="200" align="center">Jose Vicente</td>
                <td align="center"><input type="checkbox" name="checkbox" id="checkbox" /></td>
                <td align="center"><input type="checkbox" name="checkbox2" id="checkbox2" /></td>
              </tr>
              <tr bgcolor="#CCCCCC">
                <td align="center">Juanjo</td>
                <td align="center"><input type="checkbox" name="checkbox4" id="checkbox4" /></td>
                <td align="center"><input type="checkbox" name="checkbox3" id="checkbox3" /></td>
              </tr>
              <tr>
                <td width="200" align="center">Juan</td>
                <td align="center"><input type="checkbox" name="checkbox4" id="checkbox4" /></td>
                <td align="center"><input type="checkbox" name="checkbox3" id="checkbox3" /></td>
              </tr>
            </table>
            <p class="byline">&nbsp;</p>
            <input type="submit" name="Procesar" value="Confirmar" />
            <p class="left">&nbsp;</p>
<p class="byline">&nbsp;</p>
<div id="footer">
  <div> <font face="Arial Black" class="current">Designed by <a href="http://www.f8d.net">f8d</a>, modificated by Marcos Eslava</font></div>
			  </div>
			</div>
		</div>

	</div>
	</body>
</html>
A continuación os pongo el archivo que tengo de php, pero lo que no tengo muy claro si pongo todo lo que tengo que poner.

Código:
<?php

     if (isset($_POST['expediente']))
     {
         foreach ($_POST['expediente'] as $expediente_s)
             if ($expediente_s == 1){
if (!isset($_POST['Procesar'])){
echo "<h2>Se hizo submit con Checkbox nº 1</h2>";
}

}else{
echo "también se marcó el CheckBox nº $expediente_s <br />";

}
     }
if (isset($_POST['Procesar'])){
echo "<h2>Se hizo submit con Boton</h2>";
}
Bueno espero haberme explicado correctamente, soy nuevo en esto y voy un poco perdido. Gracias por adelantado.
  #2 (permalink)  
Antiguo 05/11/2010, 07:20
 
Fecha de Ingreso: noviembre-2010
Mensajes: 4
Antigüedad: 13 años, 5 meses
Puntos: 0
Respuesta: Checkbox que se borran

Se me ha olvidado decir que me he leido todos los post sobre checkbox (creo) del foro y he seguido un ejemplo que hay por el foro, pero aún asi agradecere cualquier ayuda. Gracias
  #3 (permalink)  
Antiguo 05/11/2010, 08:51
Avatar de masterojitos  
Fecha de Ingreso: julio-2008
Ubicación: Lima Callao Chucuito
Mensajes: 1.931
Antigüedad: 15 años, 9 meses
Puntos: 105
Respuesta: Checkbox que se borran

No entiendo muy bien tu codigo.... pero lo que te puedo dar es la solucion explicada.... y espero puedas desarrollarla....

Al hacer submit, debes recorrer el nombre arreglo de los checkbox con un foreach (antes preguntando si la cantidad es mayor a 0) y una vez en el bucle, preguntas si el valor es diferente de vacio, quiere decir que lo checkearon y entonces debes de nuevo checkearlo.

OMG.... ni yo me entiendo muy bien xD

Espero te haya servido de algo, sino comentame y haber si te ayudo con algun codigo de ejemplo.

Suerte
__________________
Atte. MasterOjitos :ojotes:
Todo sobre Programación Web
Las ultimas tendencias en Efectos y Recursos Web: MasterOjitos Blog
  #4 (permalink)  
Antiguo 05/11/2010, 18:05
 
Fecha de Ingreso: noviembre-2010
Mensajes: 4
Antigüedad: 13 años, 5 meses
Puntos: 0
Respuesta: Checkbox que se borran

Hola, muchas gracias por contestar y la verdad es que mucho no lo he entendido, debido a que soy totalmente novato, es mi primera página web, la verdad es que de buenas a primeras el código parece un poco raro, voy a ponerlo sin el php, que creo que no lo he hecho correctamente.

Código:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
		<title>Olivereta United.tk</title>
		<link href="style.css" rel="stylesheet" type="text/css" media="all"/>
	</head>
<body>
	<div id="container">
		<div id="main-title"><span style="font-weight: 400"><font face="Arial Black" style="font-size: 9"><span style="font-weight: 400">Olivereta United</span></font></span></div>
		<div id="header-image"></div>
		<div id="navbar">
			<font face="Arial Black" style="font-size: 9">
			<a href="Equipo.html"><span style="font-weight: 400">Equipo</span></a><span style="font-weight: 400"> ||
			</span>
            <a href="Contacto.html"><span style="font-weight: 400">Contacto</span></a><span style="font-weight: 400"> ||
                </span>
            <a href="Proximo partido.html"><span style="font-weight: 400">Próximo partido</span></a></font></div>
      			<div id="body">
     			<h1><font face="Arial">Viernes, 05/11/2010</font></h1>
			<form id="form1" action="mantener_checkbox.php" method="post">
			<div id="main-text">
            <title></title>
            <title></title>
              <p class="byline">&nbsp;</p>
              <p>&nbsp;</p>
            <table width="400" border="0" align="center">
              <tr>
                <td width="200" rowspan="2" align="center" bgcolor="#999999">Jugadores</td>
                <td colspan="2" align="center" bgcolor="#999999">Asistencia</td>
              </tr>
              <tr>
                <td width="100" align="center" bgcolor="#CCCCCC">Si</td>
                <td width="100" align="center" bgcolor="#CCCCCC">No</td>
              </tr>
              <tr>
                <td width="200" align="center" bgcolor="#CCCCCC">Nacho</td>
                <td align="center" bgcolor="#CCCCCC"><input type="checkbox" name="checkbox" id="checkbox" /></td>
                <td align="center" bgcolor="#CCCCCC"><input type="checkbox" name="checkbox2" id="checkbox2" /></td>
              </tr>
              <tr>
                <td width="200" align="center">Joaquin</td>
                <td align="center"><input type="checkbox" name="checkbox4" id="checkbox4" /></td>
                <td align="center"><input type="checkbox" name="checkbox6" id="checkbox6" /></td>
              </tr>
              <tr bgcolor="#CCCCCC">
                <td width="200" align="center">Alejandro</td>
                <td align="center"><input type="checkbox" name="checkbox4" id="checkbox4" /></td>
                <td align="center"><input type="checkbox" name="checkbox3" id="checkbox3" /></td>
              </tr>
            </table>
            <p class="byline">&nbsp;</p>
            <input type="submit" name="Procesar" value="Confirmar" />
            <p class="left">&nbsp;</p>
<p class="byline">&nbsp;</p>
<div id="footer">
  <div> <font face="Arial Black" class="current">Designed by <a href="http://www.f8d.net">f8d</a>, modificated by Marcos Eslava</font></div>
			  </div>
			</div>
		</div>
	</div>
	</body>
</html>
Luego creo que tendría que crear un código php en otro archivo para que de la información que mi intento es:

Código:
<?php
     if (isset($_POST['expediente']))
     {
         foreach ($_POST['expediente'] as $expediente_s)
             if ($expediente_s == 1){
if (!isset($_POST['Procesar'])){
echo "<h2>Se hizo submit con Checkbox nº 1</h2>";
}

}else{
echo "también se marcó el CheckBox nº $expediente_s <br />";
}
     }
if (isset($_POST['Procesar'])){
echo "<h2>Se hizo submit con Boton</h2>";
}
La verdad es que cualquier ayuda me sirve, gracias de antemano.
  #5 (permalink)  
Antiguo 05/11/2010, 21:53
Avatar de mortiprogramador
Colaborador
 
Fecha de Ingreso: septiembre-2009
Ubicación: mortuoria
Mensajes: 3.805
Antigüedad: 14 años, 7 meses
Puntos: 214
Respuesta: Checkbox que se borran

Hola
pues creo que para lo que necesitas,
es mejor que uses radios en vez de checks

por otro lado, creo que no has visto
todos los foros al respecto, pues en varios
se habla de manejar los check o radios como
si fueran arrays

ej

Código HTML:
Ver original
  1. <!-- para cada radio o check -->
  2. name=asistencia[]

y esto hará que php entienda que recibe un
array en ese campo asistencia, y allí entra
lo que te comento masterojitos

así el asunto, revisale un poco más,
ya casi lo tienes

saludos
__________________
"Si consigues ser algo más que un hombre, si te entregas a un ideal, si nadie puede detenerte, te conviertes en algo muy diferente."
Visita piggypon.com

Etiquetas: borran, checkbox
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 20:43.