doulu8537 2012-08-27 00:16
浏览 46
已采纳

too long

I have the following forms that are rendered by some PHP logic. The forms render fine; you can see the text inputs and submit button and all.

In IE the forms work as expected. The first form goes to 'index.php?subscribe=go' and the second to 'index.php?unsub=go', but in FF and Chrome, clicking the submit button reloads the page (does not go to form action). I have not checked other browsers.

I found in Firebug that the <form> tag doesn't even exist on the page in Firefox. This is very strange; check it out:

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>';
    }

This is the JS for form validation (negligible I think because it works in IE and I get the same result when commenting this script out):

<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>
  • 写回答

3条回答 默认 最新

  • drbl91357 2012-08-27 00:21
    关注

    The <form> tag doesn't exist? Unless you have code that tailors the output to the USER_AGENT, any browser that passes a given set of GET/POST input to the page should receive identical output. It's possible, of course, that they'll render the page and respond to events in (potentially significantly) different ways, but the source code should be identical.

    Post the page source and we can look and see what the issue might be.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?