Foros del Web » Programando para Internet » PHP »

Ayuda con formulario php

Estas en el tema de Ayuda con formulario php en el foro de PHP en Foros del Web. Hola a todos.. soy nuevo en escribir en este foro pero no primerizo en leeerlo... Me gustaria que me ayudarais con este formulario en php. ...
  #1 (permalink)  
Antiguo 18/02/2011, 08:07
 
Fecha de Ingreso: febrero-2011
Mensajes: 1
Antigüedad: 13 años, 1 mes
Puntos: 0
Ayuda con formulario php

Hola a todos.. soy nuevo en escribir en este foro pero no primerizo en leeerlo...
Me gustaria que me ayudarais con este formulario en php. La cuestion es que cuando lo subo al FTP y lo abro en el navegador al dar a enviar me devuelve el PHP y no me abre los alert de las validaciones. Lo curioso es que en el dreamweaver en local si funciona correctamente.
El hosting que uso es el smart de piensasolutions y tiene PHP.
Os pongo los script.

---------------------------------CONTACTO.PHP-----------------------------------------
archivo contacto.php

<form method="post" onsubmit="return validar(this)" id="form1" action="gracias.php">
<fieldset>
<legend><strong>FORMULARIO</strong></legend>
<input type="hidden" name="token" value="<?php $token?>" />
<input type="hidden" name="ip" value="<?php $_SERVER['REMOTE_ADDR']?>" />
<input type="hidden" name="httpref" value="<?php $httprefe?>" />
<input type="hidden" name="httpagent" value="<?php $httpagente?>" />
<input type="hidden" name="date" value="<?php $datee?>" />
<label for="name">Nombre:*</label>
<input name="name" id="name" size="42" maxlength="50" type="text" value="" /><br /><br />
<label for="email">Mail:*</label>
<input name="email" id="email" size="42" maxlength="50" type="text" value="" /><br /><br />
<label for="provincia">Provincia:</label>
<input name="provincia" id="provincia" maxlength="50" size="42" type="text" value="" /><br /><br />
<label for="ciudad">Ciudad:</label>
<input name="ciudad" id="ciudad" size="42" maxlength="50" type="text" value="" /><br /><br />
<label for="phone">Asunto:</label>
<input name="phone" id="phone" size="42" type="text" value="" /><br /><br />
<label for="message">Mensaje:*</label>
<textarea id="message" name="message" cols="36"rows="5"></textarea><br />
</fieldset>
<fieldset>
<legend><strong>CÓDIGO ANTI SPAM</strong></legend>
<label for="uword">Inserte el c&oacute;digo de la imagen*<br />
(para evitar el Spam)</label><br />
<input type="text" name="uword" size="33" id="uword" value="" /><br /><br />
<script type="text/javascript">cimg()</script>
</fieldset>
<fieldset>
<legend><strong>ENVIAR MAIL</strong></legend>
<input type="reset" value="Borrar" />
<input type="submit" value="Enviar" />
</fieldset>
</form>
<?php
echo "<script type=\"text/javascript\">\n";
echo "<!--\n";
echo "function validar(form1) {\n";
echo "if (form1.name.value.length < 2) {\n";
echo "alert('";
echo "Inserte el nombre";;
echo "')\n";
echo "form1.name.focus();\n";
echo "return (false);}\n";
echo "var checkOK = \"ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ \" + \"abcdefghijklmnñopqrstuvwxyzáéíóú\";\n";
echo "var checkStr = form1.name.value;\n";
echo "var allValid = true;\n";
echo "var uword = hex_md5(document.getElementById('uword').value)\n" ;
echo "for (i = 0; i < checkStr.length; i++) {";
echo "ch = checkStr.charAt(i);\n";
echo "for (j = 0; j < checkOK.length; j++)\n";
echo "if (ch == checkOK.charAt(j))\n";
echo "break;\n";
echo "if (j == checkOK.length) {\n";
echo "allValid = false;\n";
echo "break;";
echo "}}\n";
echo "if (!allValid) {\n";
echo "alert('";
echo "Inserte el nombre";
echo "');\n";
echo "form1.name.focus();\n";
echo "return (false);}\n";
echo "if ((form1.email.value.indexOf ('@', 0) == -1)||(form1.email.value.length < 9) || form1.email.value.indexOf ('.', 0)== -1 ){\n";
echo "alert('";
echo "Inserte el mail";
echo "');\n";
echo "form1.email.focus();";
echo "return (false);}\n";
echo "if (form1.message.value.length < 7) {\n";
echo "alert('";
echo "Inserte el mensaje";
echo "');\n";
echo "form1.message.focus();";
echo "return (false);}\n";
echo "if (uword==cword[anum-1]) {\n";
echo "return true;}\n";
echo "else {\n";
echo "alert('";
echo "Inserte el código de la imagen";
echo "');\n";
echo "document.getElementById('uword').focus();\n";
echo "return false;}\n";
echo "return (true);}\n";
echo "-->\n";
echo "</script>\n";
?>

---------------------------------GRACIAS.PHP-----------------------------------------

y el archivo gracias.php
<?php
@import_request_variables("gpc");
$youremail = "[email protected]";
$subject = "web.org ";
$redirect = "index.php";
$secs = "5";

if(eregi("MIME-Version:",$postVars)) {
mail("[email protected]", "Form Hijack Attempt", "A spam relay was attempted from the Web site and was blocked.", "From:SpamMonitor");
die();
}

$secret = 'ssshhitsasecret';
$token = md5(rand(1, 1000).$secret);
$_SESSION['token'] = $token;

$name = stripslashes($name);
$message = stripslashes($message);
$headers .= "From: " . $name . "\r\n\r\n";
mail("$youremail", "$subject","
Nombre del remitente: $name
Su mail es: $email
\r
Vive en la provincia de: $provincia
En la ciudad : $ciudad
\r
El asunto de su mail es: $phone
Y el comnetario: \r $message
\r\r\r
IP: $ip
Información: $httpagent
Día : $date
",$headers);

$_POST['email'] = preg_replace("\r", "", $_POST['email']);
$_POST['email'] = preg_replace("\n", "", $_POST['email']);

$_SESSION['token'] = $token;
$token = md5(rand(1, 1000).$secret);
$secret = 'ssshhitsasecret';
$field = preg_replace( "/[\n\r]+/", " ", $field );

$find = array("/bcc\:/i","/Content\-Type\:/i","/cc\:/i","/to\:/i");
$_POST['email'] = preg_replace($find, "", $_POST['email']);
$message = preg_replace($find, "", message);
$email=str_replace("\r","\n", $email);
$name=str_replace("\r","\n", $name);
$provincia=str_replace("\r","\n", $provincia);
$ciudad=str_replace("\r","\n", $ciudad);
$message=str_replace("\r","\n", $message);
$phone=str_replace("\r","\n", $phone);


if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
ob_clean();
mail("$youremail", "Message Killed", "$message", "From: $name <$email>");
exit("ERROR ");
}
if (eregi('^(bcc$|content-type|mime-version|--)',$key))
print_error("Error al enviar el mail.");
?>


Muchas gracias a todos
  #2 (permalink)  
Antiguo 18/02/2011, 16:45
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 9 meses
Puntos: 2135
Tema movido desde Configuración PHP a PHP
  #3 (permalink)  
Antiguo 19/02/2011, 17:41
 
Fecha de Ingreso: febrero-2011
Ubicación: Capital Federal
Mensajes: 45
Antigüedad: 13 años, 1 mes
Puntos: 3
Respuesta: Ayuda con formulario php

A ver amigo. En primer lugar, por qué el javascript está al final de la página e impreso a través de PHP, cuando lo que vos estás haciendo ahi sencillamente es imprimir un Javascript que podría estar en el head? Eso es muy desprolijo!

Ese es todo el codigo de contacto.php? faltan las etiquetas html, head y, body.

"Me devuelve el php". Cual te devuelve, contacto o gracias? Realmente, en primer lugar, yo ordenaria ese código. De esa forma, el mismo dreamweaver podria encontrarte errores de sintaxis en la funcion validar. asimismo, agregaría las etiquetas <html><head></head><body></body> y </html>

Luego me contas como te fue. Saludos y suerte!

Etiquetas: formulario
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 21:42.