Textarea不发送提交

Textarea不发送提交

问题描述:

Arg, this is so annoying!

I've got a form with a textarea. On submit I use a piece of php to send the data of the form to my email adress. The other data is sending fine (input) but it doesn't send the textarea along!

This is de PHP:

parse_str($_POST['stuff']);
mail("name@myemailadress.nl", "Website formulier", $name, $email, $comments);

This is the code:

<form class="form" id="form" action="" method="POST" >
    <p class="name">
        <input type="text" name="name" id="name" placeholder="NAAM" >
    </p>
    <p class="email">
        <input type="text" name="email" id="email" placeholder="E-MAILADRES" >
    </p>    
    <p class="text">
        <textarea name="comments" id="bericht" placeholder="BERICHT" ></textarea>
    </p>
    <p class="submit">
        <input type="submit" id="versturen_knop" class="submitBtn" value="VERSTUREN" >
    </p>
</form>

This is the code that changes the state of the submit button for 3 seconds (message send confirmation) and triggers the PHP

$(document).ready(function(){
    $('#form').submit(function(event){
        $('.submitBtn').attr('value','BERICHT VERSTUURD!');
        setTimeout(function(){
            $('.submitBtn').attr('value','VERSTUREN');
        }, 2000);
        var stuff = $('#form').serialize();
        jQuery.ajax({
            type: 'POST',
            url: 'mail.php', 
            data:{ 'stuff':stuff, }
        });
        //Prevents form submission
        return false;        
    });
});

I hope you can help!

Try this code it works,

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<form class="form" id="form" action="" method="POST" >

            <p class="name">
            <input type="text" name="name" id="name" placeholder="NAAM" >
            </p>

            <p class="email">
            <input type="text" name="email" id="email" placeholder="E-MAILADRES" >
            </p>    

            <p class="text">
            <textarea name="comments" id="comments" placeholder="BERICHT" ></textarea>
            </p>

            <p class="submit">
            <input type="submit" id="versturen_knop" class="submitBtn" value="VERSTUREN" >
            </p>
            </form>
        <script>    

            $(document).ready(function(){
$('#form').submit(function(event){
    $('.submitBtn').attr('value','BERICHT VERSTUURD!');

    setTimeout(function(){
        $('.submitBtn').attr('value','VERSTUREN');
    }, 2000);

    //var stuff = $('#form').serialize();

    jQuery.ajax({
        type: 'POST',
        url: 'mail.php', 
        data : $('#form').serialize(),
        dataType: "json"
    });

    //Prevents form submission
    return false;        
});
});

</script>



<?php
parse_str($_POST['stuff']);

mail("aa@ss.com", "Website formulier", "$name, $email, $comments");



?>

You need to add entire contents in double quotes. I have tested it, it works fine.

Try this instead

<?php
    mail("name@myemailadress.nl", "Website formulier", $_POST['name'], $_POST['email'], $_POST['comments']);
?>

Based on the circumstances, I suspect you are using a rich text editor like CKEdit or TinyMCE on your textarea.

If such is the case, you should know that these editors do not directly influence the textarea's text, and you must call a special editor-specific method to update it's contents. This method is called automatically on form submit, but for serializing and submitting forms via ajax it is not as straightforward.

If this is the case, please let me know which editor you are using and I can tell you how to correctly prepare the textarea for serialization.

Change following line

data : { 'stuff':stuff, }

to

data : stuff

or you can use

data : $('#form').serialize();

or you may try

data : {
    'name' : $('#name').val(),
    'email' : $('#email').val(),
    'comments' : $('#bericht').val()
}

and retrieve using

$_POST['name']
$_POST['email']
$_POST['comments']