jquery POST不发送textarea?

时间:2014-02-08 21:12:59

标签: php jquery html forms textarea

我使用以下脚本来处理联系表单:

$(document).ready(function(){
 /* attach a submit handler to the form */
 $("#contact_form").submit(function(event) {
 /* stop form from submitting normally */  
 event.preventDefault();

/* get some values from elements on the page: */
var $form = $( this ),
//Get the first value
nombre= $form.find( 'input[name="nombre"]' ).val(),
   //get second value
  email = $form.find( 'input[name="email"]' ).val(),
//get thirdvalue
mensaje = $form.find( 'input[name="mensaje"]' ).val(),    
//get the url. action="count.php"
url = $form.attr( 'action' );

  /* Send the data using post */
  var posting = $.post( url, { nombre: nombre, email: email, mensaje: mensaje} );

/* Put the results in a div */
posting.done(function( data ) {

$( "#contact_form" ).empty().append( data );
});
});
});    

然后conctact.php发送一封电子邮件并显示成功或失败消息:

<?php
        if (isset($_POST['email']))
           //if "email" is filled out, send email
          {
           //send email
          $email = $_POST['email'] ;
           $nombre = $_POST['nombre'] ;
           $mensaje = $_POST['mensaje'] ;

            mail("some.weird.email.address@server.com", $nombre,
           $mensaje,  $email);

            echo "<div data-alert class='alert-box success radius'>
              Su mensaje nos ha sido enviado.<br>Agradecemos que se haya comunicado con 
                 nosotros.
               <a href='#' class='close'>&times;</a>
               <a href='index.html'>Volver al sitio</a>
               </div>";

           }

          else {
             echo "<div data-alert class='alert-box warning radius'>
              Pedimos disculpas, no hemos podido enciar el mensaje.
               <br>Por favor vuelva a
               intentarlo más tarde.
               <a href='catalejo.info/index.html'>Volver al sitio</a>

               <a href='#' class='close'>&times;</a>
               </div>";
            }
        ?>

表单有三个值,两个输入和一个textarea,输入的值正在通过,但textarea不是。这可能是什么问题?任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

我想这是textarea:

mensaje = $form.find( 'input[name="mensaje"]' ).val(),

此行不用于textarea的输入 你应该用这个替换它:

mensaje  = $form.find('textarea[name="mensaje"]').val();