Ver Mensaje Individual
  #1 (permalink)  
Antiguo 04/10/2007, 17:37
mtmunozs
 
Fecha de Ingreso: octubre-2007
Mensajes: 19
Antigüedad: 16 años, 7 meses
Puntos: 0
Necesito ayuda

Muy buenas antes que nada gracias por este sitio es muy importante para los que trabajamos en diseno web, tengo una pregunta estoy aprendiendo php y la verdad se casi nada, y estoy trabajando casi todo con wizard, estoy creando un formulario que almacenan los datos en una base de datos mysql, esto esta bien excelente, estoy intentando validar dicho formulario por medio de java script, el caso es que aun con la validacion siempre me muestra una pagina de error, y lo que quiere es que me aparesca una pagina que yo quiero disenar diciendome los errores o mejor dicho los campos que faltan en dicho formulario y regresar, de antemano muchas gracias, a continuacion muestro el codigo fuente para que alguien me ayude:

<?php require_once('Connections/comentarios.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO comentariosgt (nombre, correo, comentario) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['nombre'], "text"),
GetSQLValueString($_POST['correo'], "text"),
GetSQLValueString($_POST['comentario'], "text"));

mysql_select_db($database_comentarios, $comentarios);
$Result1 = mysql_query($insertSQL, $comentarios) or die(mysql_error());

$insertGoTo = "gracias.html";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_comentarios, $comentarios);
$query_RS_Comentarios = "SELECT * FROM comentariosgt";
$RS_Comentarios = mysql_query($query_RS_Comentarios, $comentarios) or die(mysql_error());
$row_RS_Comentarios = mysql_fetch_assoc($RS_Comentarios);
$totalRows_RS_Comentarios = mysql_num_rows($RS_Comentarios);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<link href="estilo.css" rel="stylesheet" type="text/css" />
<script>
function validar(){
//valido el nombre
if (document.form1.nombre.value.length==0){
alert("Tiene que escribir su nombre")
document.form1.nombre.focus()
return 0;
}
//valido el correo Electronico
if (document.form1.correo.value.length==0){
alert("Escriba su correo Electronico")
document.form1.correo.focus()
return 0;
}
//valido el correo Electronico
if (document.form1.comentario.value.length>=300){
alert("El comentario no debe contener mas de 300 caracteres")
document.form1.comentario.focus()
return 0;
}
//el formulario se envia
alert("Muchas gracias por enviar el formulario");
document.form1.submit();
}
</script>
</head>

<body>
<br />
<table width="700" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>Tu comentario es muy importante</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td align="center"><form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1" onsubmit="validar()">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">Nombre:</td>
<td align="left" valign="baseline"><input type="text" name="nombre" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Correo:</td>
<td align="left" valign="baseline"><input type="text" name="correo" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right" valign="top">Comentario:</td>
<td align="left" valign="baseline"><textarea name="comentario" cols="50" rows="5"></textarea> </td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">&nbsp;</td>
<td align="left"><input name="submit" type="submit" value="Enviar" /><input type="reset" value="Cancelar" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form></td>
</tr>
<tr>
<td align="center">&nbsp;</td>
</tr>
<tr>
<td align="left">Si quieres ver los comentarios has clic <a href="consulta_comentarios.php" target="iglesia">aqui</a> </td>
</tr>
<tr>
<td align="center">&nbsp;</td>
</tr>
<tr>
<td align="center">Dios les bendiga </td>
</tr>
</table>

<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($RS_Comentarios);
?>