HTML5 php联系表单脚本确认


HTML5 php contact form script confirmation

我在脚本确认时遇到了一些问题。按照标准,它设置为隐藏联系表单并显示确认消息,但它不适用于所有浏览器。经过一些测试,我意识到它不适用于大多数IE版本,这些版本约占访问者的40%。

如何将隐藏和显示味精替换为"谢谢.html"?我猜这是有效的,因为大多数IE尽管设法隐藏了表单,但无法显示确认消息。"header"中的代码当前为:

<script src="php/js/jquery.validate.js"></script>
<script src="php/js/jquery.placeholder.js"></script>
<script src="php/js/jquery.form.js"></script>
<script>
$(function(){
$('#contact').validate({
submitHandler: function(form) {
    $(form).ajaxSubmit({
    url: 'thankyou.php',
    success: function() {
    $('#contact').hide();
    $('#contact-form').append("<p class='thanks'>Thank you! The message was sent.</center></p>")
    }
    });
    }
});         
});
</script>

已解决。

阅读 http://groups.google.com/group/jquery-en/browse_thread/thread/58a9cbc1068d28c0/eb4bedb2cc36b126?pli=1

我添加了一个条件脚本

<head>
<!--[if IE]>
<script >
document.createElement("section"); 
</script >
<![endif]-->

http://plungjan.name/test/testform_validation.html

您需要做的是附加到IE理解的元素。

如果您不需要条件脚本,请在页面末尾添加一个div 并附加到该脚本,如下所示:http://plungjan.name/test/testformvalidation.html


其他问题:我得到了

Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.0.3705; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.1)
Timestamp: Tue, 17 May 2011 13:15:29 UTC

Message: Unexpected call to method or property access.
Line: 5569
Char: 5
Code: 0
URI: http://code.jquery.com/jquery-1.6.1.js

似乎最终不受支持

当我在最后之前添加catch(e) {}时 - 错误消失了

resolveWith: function( context, args ) {
  if ( !cancelled && !fired && !firing ) {
    // make sure args are available (#8421)
    args = args || [];
    firing = 1;
    try {
      while( callbacks[ 0 ] ) {
        callbacks.shift().apply( context, args );
      }
    }
    catch(e) { /* ADDED BY ME */ }
    finally {
      fired = [ context, args ];
      firing = 0;
    }
  }
  return this;
},

替换

$('#contact').hide();     $('#contact-form').append("<p class='thanks'>Thank you! The message was sent.</center></p>")

window.location.href="thankyou.html";

简单的解决方案。当然,此代码使用相对路径,将"谢谢.html"替换为该页面的实际位置。

另外,去掉写</center>的部分。您不应该在该代码中添加结束标记,中心对象应该已经正确关闭。也许这就是IE不显示它的问题。HTML 编码错误。

编辑:是的,如果你愿意,你可以通过$(window.location).attr('href', 'thankyou.html');使用jQuery虽然这对我的原始解决方案没有任何好处,但它更容易阅读和理解,更不用说速度更快了。

将 thankyou.php 设置为表单操作,并仅使用 jQuery validate() 来确保表单字段已完成:

<script>
    $(function(){
       $('#contact').validate({
            // Validate your form fields here
       });
    });
</script>
...
<form id="contact" action="thankyou.php" method="post">

使用感谢.php处理表单提交并将用户重定向到感谢.html:

<?php
header("Location: thankyou.html");
?>

此方法将消除对 AJAX 调用和表单隐藏的需求。