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();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学中在线排序的时间在线排序的在线LPT算法
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧