Foros del Web » Programando para Internet » PHP »

FormularioWeb en PHP

Estas en el tema de FormularioWeb en PHP en el foro de PHP en Foros del Web. Hola, estoy intentando hacer un formulario para mi web y lo tengo casi resuelto, pero me gustaria que cuando envia el mail por el servidor ...
  #1 (permalink)  
Antiguo 15/05/2009, 12:51
 
Fecha de Ingreso: septiembre-2007
Mensajes: 9
Antigüedad: 16 años, 6 meses
Puntos: 0
FormularioWeb en PHP

Hola, estoy intentando hacer un formulario para mi web y lo tengo casi resuelto, pero me gustaria que cuando envia el mail por el servidor en lugar de imprimir un mensaje en pantalla con la funcion "echo" lo haga a una direccion web. El codigo de mi formulario es el siguiente:

Código:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Nombre</title>
</head>




<body>
	
<? 
if (!$HTTP_POST_VARS){ 
?> 
<form action="envia_form_php.php" method=post>

<table border="0" width="100%" id="table1">
		<tr>
			<td width="74"><font face="Tahoma" color="#800000">Nombre:</font></td>
			<td>
			<input type="text" name="Nombre" size="20" value="Click aquí para agregar su nombre"></td>
		</tr>
		<tr>
			<td width="74"><font face="Tahoma" color="#800000">Apellido:</font></td>
			<td>
			<input type="text" name="Apellido" size="20" value="Click aquí para agregar su apellido"></td>
		</tr>
		<tr>
			<td width="74"><font face="Tahoma" color="#800000">e-Mail:</font></td>
			<td>
			<input type="text" name="Mail" size="29" value="Click aquí para agregar su e-mail"></td>
		</tr>
		<tr>
			<td width="74"><font face="Tahoma" color="#800000">Edad:</font></td>
			<td>
			<input type="text" name="Edad" size="3"></td>
		</tr>
		<tr>
			<td width="74"><font face="Tahoma" color="#800000">Sexo:</font></td>
			<td>&nbsp; <input type="radio" value="V1" checked name="SexoM">Masculino&nbsp;&nbsp;
			<input type="radio" name="SexoF" value="V2">Femenino</td>
		</tr>
		<tr>
			<td width="74"><font face="Tahoma" color="#800000">Colegio:</font></td>
			<td>&nbsp;</td>
		</tr>
		<tr>
			<td width="74"><font face="Tahoma" color="#800000">Grado:</font></td>
			<td>&nbsp;</td>
		</tr>
		<tr>
			<td width="74"><font face="Tahoma" color="#800000">País:</font></td>
			<td><select size="1" name="Pais">
			<option>Argentina</option>
			<option>Bolivia</option>
			<option>Chile</option>
			<option>Uruguay</option>
			</select></td>
		</tr>
	</table>
	<table cellpadding="0" cellspacing="0" width="908" height="19">
	
		<tr>
			<td width="908" height="19"></td>
		</tr>
	</table>
	<table cellpadding="0" cellspacing="0" width="907">
	
		<tr>
			<td height="25" valign="top"><font face="Tahoma" color="#800000">¿En 
			qué área o áreas de la investigación te interesa participar?</font></td>
		</tr>
	</table>
	<div align="left">
		<table cellpadding="0" cellspacing="0" width="907" height="19" align="left">
		
			<tr>
				<td height="19" width="114" rowspan="2">&nbsp;</td>
				<td height="19" width="793" rowspan="2" valign="top">
				<font face="Tahoma">
				<input type="checkbox" name="Encuesta1" value="ON"> Recabar 
				datos<br>
				<input type="checkbox" name="Encuesta2" value="ON"> 
				Experimentación<br>
				<input type="checkbox" name="Encuesta3" value="ON"> Elaboración 
				de conclusiones<br>
				<input type="checkbox" name="Encuesta4" value="ON"> Estadísticas 
				de resultado</font></td>
			</tr>
		</table>
		<p>&nbsp;</div>
	<p>&nbsp;</p>
	<table cellpadding="0" cellspacing="0" width="907">

		<tr>
			<td height="25"><font face="Tahoma" color="#800000">Cuéntanos sobre 
			que te gustaría investigar</font></td>
		</tr>
	</table>
	<table cellpadding="0" cellspacing="0" width="907">

		<tr>
			<td height="30">
			<textarea rows="10" name="Comentario" cols="45">Ingrese su comentario aquí</textarea></td>
		</tr>
	</table>
	<p><input type="submit" value="Enviar" name="B1"><input type="reset" value="Restablecer" name="B2"></p>
	
	</form> 
<? 
}else{ 
	$cuerpo = "Formulario enviado\n"; 
	$cuerpo .= "Nombre: " . $HTTP_POST_VARS["Nombre"] . "\n"; 
	$cuerpo .= "Apellido: " . $HTTP_POST_VARS["Apellido"] . "\n";
	$cuerpo .= "Email: " . $HTTP_POST_VARS["Mail"] . "\n";
	$cuerpo .= "Email: " . $HTTP_POST_VARS["Edad"] . "\n";
	$cuerpo .= "Sexo: " . $HTTP_POST_VARS["SexoF"] . "\n";
	$cuerpo .= "Pais: " . $HTTP_POST_VARS["Pais"] . "\n";
	$cuerpo .= "Encuesta: " . $HTTP_POST_VARS["Encuesta1"] . "\n";
	$cuerpo .= "Encuesta: " . $HTTP_POST_VARS["Encuesta2"] . "\n";
	$cuerpo .= "Encuesta: " . $HTTP_POST_VARS["Encuesta3"] . "\n";
	$cuerpo .= "Encuesta: " . $HTTP_POST_VARS["Encuesta4"] . "\n";
	$cuerpo .= "Comentario: " . $HTTP_POST_VARS["Comentario"] . "\n";
	
	//mando el correo... 
    mail("miMail","Formulario recibido",$cuerpo); 

    //doy las gracias por el envío 
    echo "Gracias por rellenar el formulario. Se ha enviado correctamente.";

} 
?> 


</body>

</html>
He leido que se puede hacer con la funcion header() de PHP, pero no logro saber donde la tengo que incluir. Espero puedan ayudarme, muchas gracias desde ya!
  #2 (permalink)  
Antiguo 15/05/2009, 12:57
 
Fecha de Ingreso: junio-2008
Ubicación: Capital Federal xD
Mensajes: 1.208
Antigüedad: 15 años, 10 meses
Puntos: 35
Respuesta: FormularioWeb en PHP

header location es utilizada para redireccionar la pagina
Luego de haber enviado el email puedes declarar:
Código PHP:
header('Location: http://www.tupaginaDestino.com/'); 
  #3 (permalink)  
Antiguo 15/05/2009, 13:29
Avatar de hector2c  
Fecha de Ingreso: noviembre-2007
Ubicación: Perú - Tacna
Mensajes: 979
Antigüedad: 16 años, 4 meses
Puntos: 25
Pregunta Respuesta: FormularioWeb en PHP

ten cuidado con el header(), su función no es netamente la re-dirección, en algunos hosting, servidores, suelen haber problemas, lo digo por experiencia...

recomiendo usar javascript para redireccionar:

Código PHP:
window.location 'la_pagina.php'
nos vemos!!
__________________
blog: hector2c.wordpress.com
email: [email protected]
  #4 (permalink)  
Antiguo 15/05/2009, 14:29
 
Fecha de Ingreso: septiembre-2007
Mensajes: 9
Antigüedad: 16 años, 6 meses
Puntos: 0
Respuesta: FormularioWeb en PHP

muchas gracias por sus respuestas, con la funcion header no tuve caso, no pude hacerla funcionary con la funcion location me tira el siguiente error:

Parse error: syntax error, unexpected '='

en caso de que si el mail fue enviado lo mande a una pagina de confirmacion y en caso contrario a una de error, como deberia ponerlo correctamente en el codigo?

Código:
if (mail("eMail","Formulario recibido",$cuerpo)) 
          window.location = 'confirmacion.html';
else 
          window.location = 'error.html';
Aunque me da problema en el simbolo "="
  #5 (permalink)  
Antiguo 15/05/2009, 14:35
 
Fecha de Ingreso: junio-2008
Ubicación: Capital Federal xD
Mensajes: 1.208
Antigüedad: 15 años, 10 meses
Puntos: 35
Respuesta: FormularioWeb en PHP

window.location
es codigo javascript no php.
Deberas encerrarlo en un script
  #6 (permalink)  
Antiguo 15/05/2009, 15:08
 
Fecha de Ingreso: septiembre-2007
Mensajes: 9
Antigüedad: 16 años, 6 meses
Puntos: 0
Respuesta: FormularioWeb en PHP

puedo insertar un codigo de javascript dentro de un php? disculpa si mi pregunta es muy ignorante es que de programacion hoy por hoy se lo basico, pero se leer un codigo. que comandos debo agregar para encerrarlo en un javascript? muchas gracias por la respuesta
  #7 (permalink)  
Antiguo 15/05/2009, 15:15
 
Fecha de Ingreso: junio-2008
Ubicación: Capital Federal xD
Mensajes: 1.208
Antigüedad: 15 años, 10 meses
Puntos: 35
Respuesta: FormularioWeb en PHP

Si se puede, de la misma manera que "creas" html.
Código PHP:
<?php
if (mail("eMail","Formulario recibido",$cuerpo)) ?>
<script language="JavaScript" type="text/JavaScript">
          window.location = 'confirmacion.html';
</script><?
else {?>
         <script language="JavaScript" type="text/JavaScript">
          window.location = 'error.html';
         </script><?
}
Tambien puedes usar echo para mostrar el codigo script, a mi me gusta más este modo.
  #8 (permalink)  
Antiguo 15/05/2009, 15:23
 
Fecha de Ingreso: septiembre-2007
Mensajes: 9
Antigüedad: 16 años, 6 meses
Puntos: 0
muchas gracias por la rapida respuesta, cuando llegue a casa lo pruebo y les cuento, en este momento estoy en clases de diseño web...

queria saber si el codigo de "doylelives" esta bien programado ya que el servidor me tira el siguiente error:

Parse error: syntax error, unexpected '<'

sigo probando alguna solucion si la consigo respondo

Última edición por GatorV; 16/05/2009 a las 19:17
  #9 (permalink)  
Antiguo 16/01/2014, 00:36
 
Fecha de Ingreso: enero-2014
Mensajes: 1
Antigüedad: 10 años, 3 meses
Puntos: 0
fgjdfikekr

999 [url=http://talenabennett.com/ugg-boots-cheap/]buy ugg boots cheap[/url] Listen on the trade around the Hammond B3 and also the electrical guitar.
[url=http://morristeamonline.com/ugg-boots-clearance.html]kids ugg boots clearance[/url] Now, that was a bit uncomfortable given that a yr prior I'd fulfilled Kanye in Vegas and we experienced a minute! NOT SEXUAL! I REPEAT, KANYE WEST and that i Never have had sexual relations," she emphasises inside of the book.
[url=http://holdisraelaccountable.net/cheap-bengals-jerseys.html]cheap cincinnati bengals jerseys[/url] Reporter: Encouraging females to routinely test in with their doctors, anything she opened up about on "gma." The concept is about preventive medical as a result of I had no signs and symptoms and customarily thyroid most cancers is very refined simms.
[url=http://snottygifts.com/cheapjerseys/]cheap authentic nfl jerseys[/url] It is really a definite chocolate far too, oscillating invisibly somewhere between semisweet, milk, and bitter/black it brings to brain a pastry chef's calme, dewy, sugared, cocoadoped pill lying freshly constructed on wax paper.".
[url=http://www.lawnservicenaplesfl.com/michael-kors-outlet.html]michael kors outlet[/url] The Descendants star, Shailene Woodley, had no these types of predicament past night as she faced a concern so common to girls the earth greater than.
[url=http://www.artviewamerica.com/cheap_football_jerseys/]cheap custom football jerseys[/url] And vice versa." Kate Hudson, who are advised to certainly day Terrence Howard.
  #10 (permalink)  
Antiguo 16/01/2014, 02:51
 
Fecha de Ingreso: octubre-2012
Mensajes: 135
Antigüedad: 11 años, 6 meses
Puntos: 8
Respuesta: FormularioWeb en PHP

Dinos la linea del error. O hay un < de más o en el if está mal.
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 12:52.