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条)

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序