我有一些PHP逻辑呈现的以下表单。表单渲染正常;你可以看到文本输入和提交按钮等。为什么这些<form>不被FF和Chrome识别?
在IE中,表单按预期工作。第一种形式为'index.php?subscribe = go',第二种形式为'index.php?unsub = 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._-][email protected][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>
我们可以看到上面的网页的网址。 – 2012-08-27 00:22:35
它在我的本地机器上,一个WAMP服务器。再次,它在IE中运行良好,但有一些错误或者东西,使FF和Chrome不呈现窗体标签。 – khaverim
无法调试我无法看到,上传或? – 2012-08-27 00:29:06