【问题标题】:jquery POST not sending textarea?jquery POST不发送textarea?
【发布时间】:2014-02-08 21:12:59
【问题描述】:

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

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

表单具有三个值,两个输入和一个文本区域,输入的值通过但文本区域的不是。这里可能是什么问题?任何帮助将不胜感激。

【问题讨论】:

  • 问题> mensaje = $form.find( 'input[name="mensaje"]' ).val(), 你应该选择 textarea> textarea[name='mensaje']。

标签: php jquery html forms textarea


【解决方案1】:

我想这是文本区域:

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

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

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

【讨论】:

    猜你喜欢
    • 2019-12-20
    • 1970-01-01
    • 2012-02-05
    • 1970-01-01
    • 2015-12-08
    • 1970-01-01
    • 2014-04-01
    • 2013-10-10
    • 1970-01-01
    相关资源
    最近更新 更多