2012-08-27 41 views
-2

我有一些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> 
+0

我们可以看到上面的网页的网址。 – 2012-08-27 00:22:35

+0

它在我的本地机器上,一个WAMP服务器。再次,它在IE中运行良好,但有一些错误或者东西,使FF和Chrome不呈现窗体标签。 – khaverim

+0

无法调试我无法看到,上传或? – 2012-08-27 00:29:06

回答

0

<form>标签不存在?除非您有将输出定制到USER_AGENT的代码,否则任何将给定的一组GET/POST输入传递给页面的浏览器应该会得到相同的输出。当然,他们可能会渲染页面并以(潜在地)不同的方式响应事件,但源代码应该是相同的。

发布页面源代码,我们可以看看问题可能是什么。

+0

我查看了源代码并找到了问题并发布了答案;感谢Adam。 – khaverim

1

如果您在表单中使用POST方法,所有参数都应该通过INPUT html元素(即action =“index.php?subscribe = go”和action =“index.php?unsub = go”是错误的)。

+0

发布数据与表单提交中URL传递的GET数据分开处理(即它们不是'错误')。我现在就开始工作并发布了答案。 – khaverim

+0

使用HTTP“post”方法,表单数据集包含在表单主体中并发送给处理代理。恕我直言,你不应该混合得到和发布方法。 – freedev

+0

我同意不使用两者的'一般做法',但您可以通过HTTP传递GET和POST数据,没有任何问题。它们是独立的实体,可以这样访问。在我的情况下,它可以非常有用,同时使用POST和GET数据。 – khaverim

-1

这是一个奇怪的WAMP问题。我在文件中产生了一些其他的PHP代码,这些代码产生了WAMP错误(但是在现场没有错误),我一直忽略它,因为它没有意义。 '未定义索引'就是它的名称,当你使用$ _POST [例子]而不是$ _POST ['example']调用一个PHP变量时会出现错误。最荒谬的。

因此,WAMP吐出一堆HTML(错误<table> s),它与我的页面上的其他表单混淆在一起。 IE可以处理那里搞砸的形式,我的表单(显示问题)正常工作,而FF/Chrome不能。

希望这可以帮助别人。

+0

它不会帮助任何人,除非你发布生成的html。 – Alohci

+0

不,这个概念很简单,并且可以理解为没有WAMP的HTML吐出乱七八糟:页面上的其他形式+ WAMP未定义的索引错误(在活动站点上不会发生这种错误)=表单呈现正确的问题。 – khaverim

相关问题