[英]HTML5 php contact form script confirmation
我在确认脚本时遇到了麻烦。 按照标准,它设置为隐藏联系表单并显示确认消息,但不适用于所有浏览器。 经过一些测试,我意识到它不适用于大多数IE版本,这大约占我访问者的40%。
如何将hide-and-show-msg替换为“ thankyou.html”? 我猜测这是可行的,因为大多数IE尽管设法隐藏了表单,但仍未显示确认消息。 “标头”中的代码当前为:
<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>
解决了。
我添加了条件脚本
<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";
简单的解决方案。 当然,此代码使用相对路径,将“ thankyou.html”替换为该页面的实际位置。
另外,取出表示</center>
。 您不应该在该代码中添加结束标记,中心对象应该已经正确关闭。 也许这就是为什么IE无法显示它的问题。 HTML编码错误。
编辑:是的,如果您这样倾斜,则可以通过$(window.location).attr('href', 'thankyou.html');
使用jQuery $(window.location).attr('href', 'thankyou.html');
尽管这对我的原始解决方案没有任何好处,该解决方案更易于阅读和理解,更不用说更快了。
将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调用和表单隐藏的需求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.