weixin_33726313 2016-06-28 07:43 采纳率: 0%
浏览 57

提交后重置表格

I have a form which if the email is wrong gives me an error message while i stay on the same page, this is possible because i used ajax. Now I'm trying to achieve when i submit the form and the return is an error that the forms reset.

I tried reset(); but it didn't work.

<?php
    header("Refresh:7; url=contact.php");
    $email = $_POST['subscribefield'];

    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        echo "Dit emailadres klopt niet";
      reset($email);
    }


    $to = "flash1996mph@hotmail.com";
    $subject = "Abonee voor de nieuwsbrief";
    $body = "$email 
 Heeft zich aangemeld voor de nieuwsbrief";

    mail($to, $subject, $body);
    echo "U heeft zich zojuist aangemeld voor de vandenberg nieuwsbrief";
?>

and

$('form.subscribe').on('submit', function() {
    var that = $(this),
    url = that.attr('action'),
    method = that.attr('method'),
    data = {};

    that.find('[name]').each(function(index, value) {
        var that = $(this),
        name = that.attr('name'),
        value = that.val();

        data[name] = value;
    });

    $.ajax({
        url: url,
        type:method,
        data: data,
        success: function(response) {
            $('#success-message').html(response).show();
            setTimeout(function() {
                $('#success-message').fadeOut('slow');
            }, 2000); 
        }
    });
    return false;
});
  • 写回答

3条回答 默认 最新

  • weixin_33676492 2016-06-28 07:54
    关注

    Put this button inside your <form>:

    <input type="reset" value="Reset Form" id="resetButton" >
    

    and make a click on this button whenever you find error in return like this,

    $("#resetButton").click();
    
    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示