Foros del Web » Programando para Internet » Javascript » Frameworks JS »

formulario con ajax

Estas en el tema de formulario con ajax en el foro de Frameworks JS en Foros del Web. hola tengo un formulario que me funciona pero solo que no me aplica los saltos te linea del campo peticion no me respeta los saltos ...
  #1 (permalink)  
Antiguo 02/12/2010, 11:32
Avatar de engonga
Usuario no validado
 
Fecha de Ingreso: marzo-2002
Ubicación: Buenos Aires
Mensajes: 1.300
Antigüedad: 22 años, 1 mes
Puntos: 8
formulario con ajax

hola tengo un formulario que me funciona pero solo que no me aplica los saltos te linea

del campo peticion no me respeta los saltos de linea

y ya no se como hacerlo

form.php
Código PHP:
<div id="contact_form">
    
     <
h4Formulario de contacto </h4>
          
   <
form name="contact" method="post" action="">
               
            <
div id="form_col_esquerra">
            <
label for="nombre" id="nombre_label">Nombre</label>
            <
input type="text" name="nombre" id="nombre" size="40" value="" tabindex="1" class="text-input" />
            <
label class="error" for="nombre" id="nombre_error">Este campo es requerido.</label>
      
            <
label for="telefono" id="telefono_label">Teléfono</label>
            <
input type="text" name="telefono" id="telefono" size="40" value=""  tabindex="3"class="text-input" />
            <
label class="error" for="telefono" id="telefono_error">Este campo es requerido.</label>
            
            <
label for="poblacion" id="poblacion_label">Población</label>
              <
input type="text" name="poblacion" id="poblacion" size="40" value="" tabindex="5" class="text-input" />
              <
label class="error" for="poblacion" id="poblacion_error">Este campo es requerido.</label>
            
            <
label for="empresa" id="empresa_label">Empresa</label>
              <
input type="text" name="empresa" id="empresa" size="40" value="" tabindex="7" class="text-input" />
              <
label class="error" for="empresa" id="empresa_error">Este campo es requerido.</label>
            </
div>
            
            
            <
div id="form_col_dreta">
            <
label for="apellidos" id="apellidos_label">Apellidos</label>
              <
input type="text" name="apellidos" id="apellidos" size="40" value="" tabindex="2" class="text-input" />
              <
label class="error" for="apellidos" id="apellidos_error">Este campo es requerido.</label>
            
            <
label for="email_f" id="email_f_label">Email</label>
              <
input type="text" name="email_f" id="email_f" size="40" value="" tabindex="4" class="text-input" />
              <
label class="error" for="email_f" id="email_f_error">Este campo es requerido.</label>
            
            <
label for="provincia" id="provincia_label">Priovincia</label>
              <
input type="text" name="provincia" id="provincia" size="40" value="" tabindex="6" class="text-input" />
             <
label class="error" for="provincia" id="provincia_error">Este campo es requerido.</label>
            
            <
label for="cargo" id="cargo_label">Cargo</label>
              <
input type="text" name="cargo" id="cargo" size="40" value=""  tabindex="8" class="text-input" />
              <
label class="error" for="cargo" id="cargo_error">Este campo es requerido.</label>
            </
div>
             <
div class="neteja_sota" style="width:100%; height:5px;"></div>
      <
label for="peticion" id="peticion_label">Petición</label>
      <
textarea name="peticion" cols="75" rows="6" id="peticion" tabindex="9" class="text-input"></textarea>
                    
      <
input type="submit" name="submit" class="button" id="submit_btn" tabindex="10" value="Envia" />
    
  </
form>
      
     </
div
form.js
Código PHP:
$(function(){
  $(
'.error').hide();
  $(
'.text-input').css({backgroundColor:"#FFFFFF"});
  $(
'.text-input').focus(function(){
    $(
this).css({backgroundColor:"#F2F2F2"});
  });
  $(
'.text-input').blur(function(){
    $(
this).css({backgroundColor:"#FFFFFF"});
  });

  $(
".button").click(function() {
         $(
'.error').hide();
        
      var 
nombre = $("input#nombre").val();
        if (
nombre == "") {
      $(
"label#nombre_error").show();
      $(
"input#nombre").focus();
      return 
false;
    }
    
      var 
apellidos = $("input#apellidos").val();
        if (
apellidos == "") {
      $(
"label#apellidos_error").show();
      $(
"input#apellidos").focus();
      return 
false;
    }
    
    var 
telefono = $("input#telefono").val();
        if (
telefono == "") {
      $(
"label#telefono_error").show();
      $(
"input#telefono").focus();
      return 
false;
    }
    
    var 
email = $("input#email_f").val();
        if (
email == "") {
      $(
"label#email_f_error").show();
      $(
"input#email_f").focus();
      return 
false;
    }
     var 
poblacion = $("input#poblacion").val();
        if (
poblacion == "") {
      $(
"label#poblacion_error").show();
      $(
"input#poblacion").focus();
      return 
false;
    }
      var 
provincia = $("input#provincia").val();
        if (
provincia == "") {
      $(
"label#provincia_error").show();
      $(
"input#provincia").focus();
      return 
false;
    }
    
    var 
empresa = $("input#empresa").val();
        if (
empresa == "") {
      $(
"label#empresa_error").show();
      $(
"input#empresa").focus();
      return 
false;
    }
    
    var 
cargo = $("input#cargo").val();
        if (
cargo == "") {
      $(
"label#cargo_error").show();
      $(
"input#cargo").focus();
      return 
false;
    }
 
     var 
peticion = $("textarea#peticion").val();

        
//var dataString = 'nombre='+ nombre + '&email=' + email + '&phone=' + phone;
        
var dataString 'nombre='nombre '&apellidos=' apellidos '&telefono='telefono '&email='email '&poblacion='poblacion '&provincia='provincia '&empresa='empresa '&cargo='cargo '&peticion='peticion;
//var dataString = 'nombre='+ nombre + '&apellidos=' + apellidos + '&telefono='+ telefono + '&email='+ email+ '&poblacion='+ poblacion + '&provincia='+ provincia + '&empresa='+ empresa + '&cargo='+ cargo + '&peticion='+ peticion;


        //alert (dataString);return false;
        
    
$.ajax({
      
type"POST",
      
dataType"html",
      
url"bin/process.php",
      
datadataString,
      
success: function() {
        $(
'#contact_form').html("<div id='message'></div>");
        $(
'#message').html("<h2>Datos Enviados!</h2>")
        .
append("<p>Pronto nos pondremos en contacto.<br /><br /> <b>Gracias</b></p>")
        
        .
hide()
        .
fadeIn(1500, function() {
          $(
'#message').append("<img id='checkmark' src='imatges/check.png' />");
        });
        
      }
     });
     
// termina el ajax
    
return false;
    });
});
runOnLoad(function(){
  $(
"input#nombre").select().focus();
}); 
  #2 (permalink)  
Antiguo 02/12/2010, 11:33
Avatar de engonga
Usuario no validado
 
Fecha de Ingreso: marzo-2002
Ubicación: Buenos Aires
Mensajes: 1.300
Antigüedad: 22 años, 1 mes
Puntos: 8
Respuesta: formulario con ajax

aqui sigue...

process.php
Código PHP:
<?php

//para codificar las variables
// $firstName = iconv("UTF-8", "ISO-8859-1", $_POST['firstName']);
if ((isset($_POST['nombre'])) && (strlen(trim($_POST['nombre'])) > 0)) {
    
$nombre1 stripslashes(strip_tags($_POST['nombre']));
     
$nombre iconv("UTF-8""ISO-8859-1"$nombre1);
} else {
$name '';}

if ((isset(
$_POST['apellidos'])) && (strlen(trim($_POST['apellidos'])) > 0)) {
    
$apellidos1 stripslashes(strip_tags($_POST['apellidos']));
     
$apellidos iconv("UTF-8""ISO-8859-1"$apellidos1);
} else {
$apellidos '';}

if ((isset(
$_POST['telefono'])) && (strlen(trim($_POST['telefono'])) > 0)) {
    
$telefono stripslashes(strip_tags($_POST['telefono']));
} else {
$telefono '';}



if ((isset(
$_POST['email'])) && (strlen(trim($_POST['email'])) > 0)) {
    
$email stripslashes(strip_tags($_POST['email']));
} else {
$email '';}

if ((isset(
$_POST['poblacion'])) && (strlen(trim($_POST['poblacion'])) > 0)) {
    
$poblacion1 stripslashes(strip_tags($_POST['poblacion']));
     
$poblacion iconv("UTF-8""ISO-8859-1"$poblacion1);
} else {
$poblacion '';}

if ((isset(
$_POST['provincia'])) && (strlen(trim($_POST['provincia'])) > 0)) {
    
$provincia1 stripslashes(strip_tags($_POST['provincia']));
     
$provincia iconv("UTF-8""ISO-8859-1"$provincia1);
} else {
$provincia '';}

if ((isset(
$_POST['empresa'])) && (strlen(trim($_POST['empresa'])) > 0)) {
    
$empresa1 stripslashes(strip_tags($_POST['empresa']));
      
$empresa iconv("UTF-8""ISO-8859-1"$empresa1);
} else {
$empresa '';}

if ((isset(
$_POST['cargo'])) && (strlen(trim($_POST['cargo'])) > 0)) {
    
$cargo1 stripslashes(strip_tags($_POST['cargo']));
      
$cargo iconv("UTF-8""ISO-8859-1"$cargo1);
} else {
$cargo '';}

if ((isset(
$_POST['peticion'])) && (strlen(trim($_POST['peticion'])) > 0)) {
    
$peticion1 iconv("UTF-8""ISO-8859-1"$_POST['peticion']);
    
$peticion_astr_replace(Chr(13), "\n"$peticion1);
    
//$peticion2 =  stripslashes($peticion1);
    //$peticion2 = stripslashes(strip_tags($peticion1, "<br>"));
           
      //AddSlashes($_POST["f_serv_otros_text"]); estoperita que esrivan  /' //
    
} else {$peticion '';}

ob_start();
?>
<html>
<head>
<style type="text/css">
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<table width="550" border="1" cellspacing="2" cellpadding="2">
  <tr bgcolor="#eeffee">
    <td width="115">Nombre</td>
    <td width="415"><?=$nombre;?></td>
  </tr>
  <tr bgcolor="#eeeeff">
    <td>Apellidos</td>
    <td><?=$apellidos;?></td>
  </tr>
  <tr bgcolor="#eeffee">
    <td>Telefono</td>
    <td><?=$telefono;?></td>
  </tr>
  <tr bgcolor="#eeeeff">
    <td>Email</td>
    <td><?=$email;?></td>
  </tr>
  <tr bgcolor="#eeffee">
    <td>Poblaci&oacute;n</td>
    <td><?=$poblacion;?></td>
  </tr>
  <tr bgcolor="#eeeeff">
    <td>Provincia</td>
    <td><?=$provincia;?></td>
  </tr>
  <tr bgcolor="#eeffee">
    <td>Empresa</td>
    <td><?=$empresa;?></td>
  </tr>
   <tr bgcolor="#eeeeff">
    <td>Cargo</td>
    <td><?=$cargo;?></td>
  </tr>
   <tr bgcolor="#eeffee">
    <td>Petici&oacute;n</td>
    <td><?=$peticion_a;?></td>
  </tr>
</table>
</body>
</html>
<?
$body 
ob_get_contents();

//$to = '[email protected]';
//$email = '[email protected]';
//$fromaddress = "[email protected]";
//$fromname = "Contacto del comercio.biz";

require("phpmailer.php");

$mail = new PHPMailer();

$mail->From     "[email protected]";
$mail->FromName "Contacto del comercio.biz";
$mail->AddAddress("[email protected]");
//$mail->AddAddress("[email protected]","joan esigual");
$mail->AddBCC("[email protected]");

$mail->WordWrap 50;
$mail->IsHTML(true);

$mail->Subject  =  "Contacto del comercio.biz";
$mail->Body     =  $body;
$mail->AltBody  =  "Este texto solo esta en el body";

if(!
$mail->Send()) {
    
$recipient '[email protected]';
    
$subject 'Contact form failed';
    
$content $body;    
  
mail($recipient$subject$content"From: [email protected]\r\nReply-To: $email\r\nX-Mailer: DT_formmail");
  exit;
}
?>

Etiquetas: ajax, 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 11:20.