duanjiangzhi6851 2013-07-10 07:45
浏览 191
已采纳

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!

  • 写回答

4条回答

  • dongyong1897 2013-07-10 08:52
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站