Atendiendo a como funciona PHP y no a que estoy metiendo PHP entre el HTML (concepto que hay que tener claro). ... quedarìa:
Código PHP:
<?
if ($_POST['Submit']=="Enviar")
{
$Empresa1= $_POST["Empresa"];
$cuerpo = "Formulario enviado\n";
$cuerpo .= "Empresa: ".$_POST["Empresa"]. "\r\n";
$cuerpo .= "Nombre: " . $_POST["Nombre"] . "\r\n";
$cuerpo .= "Apellidos: ". $_POST["Apellidos"]. "\r\n";
$cuerpo .= "Email: " . $_POST["E-mail"] . "\r\n";
$cuerpo .= "Consulta: " ."\r\n". $_POST["Consulta"] . "\r\n";
$res=mail("[email protected]","Consulta desde Internet de ".$Empresa1,$cuerpo) or die ("Hubo un error");
if ($res) {
header ("Location: $_SERVER['PHP_SELF']?msg=ok");
exit;
} else {
header ("Location: $_SERVER['PHP_SELF']?msg=error");
exit;
}
?>
<html>
<head>
<script language="javascript" type="text/javascript">
function validar(objFormulario)
{
if (objFormulario.elements["Empresa"].value != "")
{
if (objFormulario.elements["Nombre"].value != "")
{
if (objFormulario.elements["Apellidos"].value != "")
{
if (objFormulario.elements["E-mail"].value != "")
{
if (objFormulario.elements["Consulta"].value != "")
{
if (objFormulario.elements["tlf"].value != "")
{
alert ("Su consulta se ha enviado con exito");
if (!isNaN(parseInt(objFormulario.elements["tlf"].value)))
{
return(true);
}
else
{
alert ("Formato incorrecto en el campo TELÉFONO");
return(false);
}
}
else
{
alert ("Rellene el campo TElËFONO");
return(false);
}
}
else
{
alert ("Haga su consulta");
return(false);
}
}
else
{
alert ("Rellene el campo E-mail");
return(false);
}
}
else
{
alert ("Rellene el campo Apellidos");
return(false);
}
}
else
{
alert ("Rellene el campo Nombre");
return(false);
}
}
else
{
alert ("Rellene el campo Empresa");
return(false);
}
}
</script>
<style type="text/css">
<!--
.Estilo1 {font-size: 24px}
-->
</style>
</head>
<body>
<form name="formulario" action="Formulariotest1.php" method="post" onSubmit="return(validar(this))">
<table width="200" border="0" align="center">
<tr>
<td><span class="Estilo16">Empresa</span></td>
<td><span class="Estilo18">
<label>
<input name="Empresa" type="text" size="32">
</label>
</span></td>
</tr>
<tr>
<td><span class="Estilo16">Nombre</span></td>
<td><span class="Estilo18">
<label>
<input name="Nombre" type="text" size="32">
</label>
</span></td>
</tr>
<tr>
<td><span class="Estilo16">Apellidos</span></td>
<td><span class="Estilo18">
<label>
<input name="Apellidos" type="text" size="32">
</label>
</span></td>
</tr>
<tr>
<td><span class="Estilo16">E-mail</span></td>
<td><span class="Estilo18">
<label>
<input name="E-mail" type="text" size="32">
</label>
</span></td>
</tr>
<tr>
<td colspan="2" align="center"><span class="Estilo16">Consulta
<label></label>
</span> <span class="Estilo18">
<label></label>
</span></td>
</tr>
</table>
<table width="217" border="0" align="center">
<tr>
<td><label>
<textarea name="Consulta" cols="40" rows="6" wrap="hard"></textarea>
</label></td>
</tr>
</table>
<table width="217
" border="0" align="center">
<tr>
<td><label>
<div align="center">
<input type="submit" name="Submit" value="Enviar">
</div>
</label></td>
<td><label>
<div align="center">
<input type="reset" name="Submit2" value="Borrar">
</div>
</label></td>
</tr>
</table>
</form>
<p>
<?
if (isset($_GET['msg'])){
echo "Hay un mensaje: ".$_GET['msg'];
}
?>
</p>
</body>
</html>
Si te fijas este código .. o "redirecciona" (con lo cual NO me interesa el "HTML" que ahì genero para otra condicion) o bien presenta esa pàgina HTML donde se compone tu formulario HTML ..
Aunque redireccionas a la misma pàgina para presentar el mensaje de error/exito .. ese es el "truco" para deshacerte de las variables que se solictian re-enviar si recargas la pàgina .. asì sòlo recargas la pàgina del "formulario" generado y no la del "proceso en sì" (la del envio del e-mail).
Un saludo,