0
我使用下面的腳本來處理一個接觸的形式:jquery POST不發送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("[email protected]", $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'>×</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'>×</a>
</div>";
}
?>
的形式有三個值,兩個輸入和一個textarea,輸入的值傳遞,但textarea不是。這裏可能是什麼問題?任何幫助將不勝感激。
問題> mensaje = $ form.find( 'input [name =「mensaje」]').val(),你應該選擇textarea> textarea [name ='mensaje']。 – sinisake
沒錯,謝謝! – Ernie