我有一些PHP逻辑呈现的以下表单。形式呈现精细;您可以看到文本输入和提交按钮等等。
在IE中,表单按预期运行。第一个表单转到"index.php"?subscribe=go,第二个到index.php?unsob=go',但在FF和Chrome中,单击提交按钮会重新加载页面(不进入表单操作)。我没有检查过其他浏览器。
我在Firebug中发现<form>
标签在Firefox的页面上甚至不存在。这很奇怪;查看:
else
{
echo '<div class="subs_main">';
if (isset($_GET['subscribe']))
{
if ($_GET['subscribe'] != 'go')
{?>
Subscribe to <b>Bella Blog</b> for specials, sales, news and more!
<br />
<form action="index.php?subscribe=go" method="post" name="subscribe_form" onsubmit="return checkForm();">
Name: <input type="text" name="name" size="15" />
<br />
Email: <input type="email" name="email" size="20" />
<br />
<input type="submit" value="subscribe!" name="submit" />
</form>
<p class="unsub">You can <a href="index.php?unsub">unsubscribe</a> at any time</p>
<?php
}
else
{
// subscribe user
}
}
elseif (isset($_GET['unsub']))
{
if ($_GET['unsub'] != 'go')
{?>
Sorry to see you go! You can <a href="index.php?subscribe">re-subscribe</a> at any time!
<br />
<form onsubmit="return checkForm2()" name="unsub_form" method="post" action="index.php?unsub=go">
Email: <input type="email" name="email" size="20" />
<br />
<input type="submit" value="unsubscribe" name="submit" />
</form>
<?php
}
else
{
// process unsubscription HERE
}
}
echo '</div>';
}
这是用于表单验证的JS(我认为可以忽略不计,因为它在IE中有效,并且我在注释这个脚本时得到了相同的结果):
<script type="text/javascript" language="javascript">
function checkForm()
{
var regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+'.[a-zA-Z]{2,6}$/;
var form = document.forms.subscribe_form;
var name = form.name.value;
var email = form.email.value;
if (name == '' || email == '')
{
alert('You must enter both your name and email address!');
return false;
}
else if (!email.match(regex))
{
alert('You must enter a valid email!');
return false;
}
return true;
}
function checkForm2()
{
var form = document.forms.unsub_form;
var email = form.email.value;
if (email == '')
{
alert('You must enter an email address!');
return false;
}
return true;
}
</script>
如果在表单中使用POST方法,所有参数都应该通过INPUT html元素传递(即action="index.php?subscribe=go"和action="index.php?unsob=go"是错误的)。
<form>
标记不存在?除非您有将输出调整为USER_AGENT的代码,否则任何将给定的GET/POST输入集传递到页面的浏览器都应该收到相同的输出。当然,他们可能会以不同的方式呈现页面和响应事件(可能有很大的不同),但源代码应该是相同的。
发布页面源代码,我们可以查看问题所在。
这是一个古怪的WAMP问题。我在文件中有一些其他PHP代码生成了WAMP错误(但在实时网站上没有错误),我一直忽略了它,因为它毫无意义。"Undefined index是它的名称,当您使用$_POST[example]而不是$_POSD['example']调用PHP变量时,会出现错误。太荒谬了。
所以WAMP吐出了一堆HTML(错误<table>
s),这些HTML与我页面上的其他表单混淆了。IE可以处理混乱的表单,而我的表单(如图所示)正常工作,而FF/Chrome则不能。
希望这能帮助到别人。