【问题标题】:HTML5 php contact form script confirmationHTML5 php 联系表单脚本确认
【发布时间】:2011-08-27 04:58:36
【问题描述】:

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

如何将 hide-and-show-msg 替换为“thankyou.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>

【问题讨论】:

  • 到目前为止我已经解决了。将调查我是否可以使用您的标签修复它。你也可以用 CSS 发布完整的页面吗?

标签: php javascript forms html confirmation


【解决方案1】:

替换

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

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

简单的解决方案。当然,这段代码使用的是相对路径,将“thankyou.html”替换为该页面的实际位置。

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

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

【讨论】:

  • 你在服务器上的同一路径上有thankyou.html吗?错误 405 表示 HTTP 周期有问题,它是否适用于任何其他浏览器?可能是服务器问题。
  • 我在 $(location).attr 上进行了测试,发现错误。似乎位置对象上没有 setAttribute
  • 我在上面的代码中使用了window.location,但实际上window.location.href="thankyou.html" 就可以了。
【解决方案2】:

解决了。

阅读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

好像 finally 不支持

当我在 finally - 错误消失之前添加 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;
},

【讨论】:

  • 看我的回答,我想我知道为什么它不会显示了,因为代码中有一个关闭中心标签,并且该对象应该已经关闭,IE找不到另一个中心对象关闭并因此出错。
  • 这是可能的。但此外,IE 以不希望将内容附加到表单而著称,而是将表单包裹在 DIV 之类的容器周围并附加到该容器
  • 与我们交谈!

    -standard form stuff

  • 我看不到中心标签。因此,append 语句中的结束中心标记是不需要的,也不应该存在。
  • 原始代码在中心标签之间有感谢信息。我正在删除东西以在此处发布较小的代码并错过了。
【解决方案3】:

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

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

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

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

这种方法将消除对 AJAX 调用和表单隐藏的需要。

【讨论】:

  • 是的,很好的解决方案,甚至更好,让 PHP 文件输出 HTML,从而甚至消除了thankyou.html 的需要。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多