Ver Mensaje Individual
  #1 (permalink)  
Antiguo 26/03/2009, 09:34
mrmaria
 
Fecha de Ingreso: noviembre-2008
Mensajes: 122
Antigüedad: 15 años, 5 meses
Puntos: 4
Pregunta Boton submit y carga de formularios ante manejo de errores

Hola, estoy usando un formulario donde tengo una tabla que posee varios articulos obtenidos de la b.d. y para cada uno un checkbox. La idea es que se seleccionen varios de los arts y que para los arts seleccionados se pulse un boton que llame a un archivo "procesar.php" para que procese el script y lo ejecute solo para los arts previamente seleccionados. Uso post para mandar el array de arts seleccionados.
El problema esta en que yo quiero que si NO hay arts seleccionados que NO se llame al archivo "porcesar.php" y que quede como se inicia (luego pondré un cartel de error diciendo que no hay arts seleccionados).
Con este codigo, lo me pasa es que si no hay seleccionados -> esta bien, no llama al otro archivo php, pero si selecciono y pulso el boton, se vuelve a cargar el formulario y no pasa nada, luego si inmediatamente pulso de nuevo el boton -> ahi si llama al archivo php y se procesan.. no da error, pero no esta bien hecho, ya que debo pulsar dos veces para que se procesen mis arts elegidos.
Si pueden darme un mano, no se donde esta el error. Aquí les dejo el codigo:

<?php if (isset($_POST['btnprocesar']) && (isset($_POST['elegidos']))) { ?>
<form name="form1" action="procesar.php" method="post">
<table width="720" height="360" border="0" align="center" cellspacing="0">
<tr>
<td align="center" valign="top"><table width="720" border="0" align="center" cellspacing="0">
<tr>
<td><table width="720" border="0" cellspacing="0" align="center">
<tr>
<td>Art&iacute;culos actuales:</td>
</tr>
</table></td>
</tr>
<tr>
<td><table width="720" border="1" cellspacing="0">
<tr>
<th width="62">Seleccionar</th>
<th width="51">ID</th>
<th width="421">T&iacute;itulo</th>
<th width="81">Tema</th>
<th width="83">Autor</th>
</tr>
<?php do { ?>
<tr>
<td><div align="center">
<input name="elegidos[]" type="checkbox" value="<?php echo $recordset['id']; ?>">
</div></td>
<td><div align="center"><?php echo $recordset['id']; ?></div></td>
<td><?php echo $recordset['tit']; ?></td>
<td><?php echo $recordset['tema']; ?></td>
<td><?php echo $recordset['autor']; ?></td>
</tr>
<?php $i++; } while ($row_rArts = mysql_fetch_assoc($recordset); ?>
</table></td>
</tr>
</table>
<table width="720" border="0" cellspacing="0">
<tr>
<td><div align="right">
<input name="btnprocesar" type="submit" id="btnprocesar" value="Procesar" <?php if ($_POST['elegidos']==1) { $selected.=($recordset['id']."-"); echo $selected; } ?>>
</div></td>
</tr>
</table></td>
</tr>
</table>
</form>
<?php } else {
//echo "no hay elegidos";
//vuelvo a mostrar el formulario
?>
<form name="form1" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table width="720" height="360" border="0" align="center" cellspacing="0">
<tr>
<td align="center" valign="top"><table width="720" border="0" align="center" cellspacing="0">
<tr>
<td><table width="720" border="0" cellspacing="0" align="center">
<tr>
<td>Art&iacute;culos actuales:</td>
</tr>
</table></td>
</tr>
<tr>
<td><table width="720" border="1" cellspacing="0">
<tr>
<th width="62">Seleccionar</th>
<th width="51">ID</th>
<th width="421">T&iacute;itulo</th>
<th width="81">Tema</th>
<th width="83">Autor</th>
</tr>
<?php do { ?>
<tr>
<td><div align="center">
<input name="elegidos[]" type="checkbox" value="<?php echo $recordset['id']; ?>">
</div></td>
<td><div align="center"><?php echo $recordset['id']; ?></div></td>
<td><?php echo $recordset['tit']; ?></td>
<td><?php echo $recordset['tema']; ?></td>
<td><?php echo $recordset['autor']; ?></td>
</tr>
<?php $i++; } while ($row_rArts = mysql_fetch_assoc($recordset); ?>
</table></td>
</tr>
</table>
<table width="720" border="0" cellspacing="0">
<tr>
<td><div align="right">
<input name="btnprocesar" type="submit" id="btnprocesar" value="Procesar" <?php if ($_POST['elegidos']==1) { $selected.=($recordset['id']."-"); echo $selected; } ?>>
</div></td>
</tr>
</table></td>
</tr>
</table>
</form>
<?php } ?>

Gracias !