dongzhanlian6289
2014-02-08 21:12
浏览 62
已采纳

jquery POST不发送textarea?

I am using the following script to handle a contact form:

$(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 );
});
});
});    

Then conctact.php sends an email and shows either a succes or failure message:

<?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>";
            }
        ?>

The form has three values, two inputs and a textarea, the input's values are passing but the textarea's is not. What could be the problem here? Any help will be appreciated.

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongyunwei8596 2014-02-08 21:18
    已采纳

    i suppose that this is the textarea :

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

    this line is for input not for textarea you should replace it with this :

    mensaje  = $form.find('textarea[name="mensaje"]').val();
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题