dqf60304 2013-01-17 02:10
浏览 130

提交按钮不起作用?

I have this small test page trying to mess around and figure out PHP code, from what I understand, after filling the forms and hitting submit, something should happen. Depending on what you entered.

<!DOCTYPE html>
<html>
<head>
    <title>PHP Testing Page</title>
</head>
<body>
    <?php
        echo "Testing Page, working great!
";
        $theDate = date("M-d-Y ");
        echo "Today is " . $theDate;
        $email1 = $_POST['email1'];
        $email2 = $_POST['email2'];
        function checkEmail()
        {
            $email1 = $_POST['email1'];
            $email2 = $_POST['email2'];
            echo $email1;
            echo $email2;
                if($email1==$email2)
                {
                    echo "
E-Mail Addresses match.";
                }
                else
                {
                    echo "
Check to make sure your E-Mails match";
                }
            }
        ?>
        <form name="checkingEmail" action="." method="post">
            E-Mail: <input type="text" name="email1" value="E-Mail Here" />
            <br />
            Retype E-Mail: <input type="text" name="email2" value="Confirm E-Mail" />
            <br />
            <input type="button" value="Submit" onClick="checkEmail()">
        </form>
    </body>
</html>

After the forms are filled (via visiting page) and the Submit button is clicked, nothing happens. Can someone explain please?

********EDIT******FIXED** Found a work around! No functions, works like a charm.

<!DOCTYPE html>
<html>
<head>
    <title>PHP Testing Page</title>
</head>
<body>
    <?php
        echo "Testing Page, working great!
";
        $theDate = date("M-d-Y ");
        echo "Today is " . $theDate;
    ?>
    <form name="checkingEmail" action="test.php" method="post">
        E-Mail: <input type="text" name="email1" value="E-Mail Here" />
        <br />
        Retype E-Mail: <input type="text" name="email2" value="Confirm E-Mail" />
        <br />
        <input type="submit" value="Submit">
    </form>
    <?php 
    $email1 = $_POST["email1"];
    $email2 = $_POST["email2"];
    if($email2==null)
    {
/*I believe this just stops it from checking the rest of the conditions, that
        way it won't echo anything until someones enters valid (non-null) input*/
        $email2 = "notnull";
    }
    else if($email1==$email2)
    {
        echo "Good Job.";
    }
    else
    {
        echo "Failure to comply.";
    }
    ?>
</body>

I have the check outside of a function, so I don't have to call it or anything like that. Also, with the first if statement, if $email2 is null (When they first load it) it will simply change $email2 to "notnull" and stop checking statements because it found a valid one. (Not 100%)

  • 写回答

2条回答 默认 最新

  • douchui3933 2013-01-17 02:12
    关注

    Where is your submit button ?

    <input type="button" value="Submit" onClick="checkEmail()">
                   ^
    

    The type should be submit

    As mentioned on this answer comments, you can't call a php function from javascript.

    When you do it you'll call checkEmail from a javascript, which isn't defined.
    So, you'll get the following error:

    Uncaught ReferenceError: checkEmail is not defined
    
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条