douyuan3842 2015-06-08 07:15
浏览 65
已采纳

Enter按钮在登录页面上不起作用

I just made a login system but I can only login with pressing the button on my screen, not using the enter button on my keyboard. How can I enable this? I read something about the AcceptButton, but how do I apply this?

my code:

login.php

<?php

    require('inc/functions.php');

    session_start();

    if(checkLogedIn()){
        header("location:index.php");
        die();
    }

    include 'inc/header.php'

?>

<body>
    <div id="wrap">
                <div class="text-center">
                    <img src="img/logo.png" height="125" width="125">
                </div>
        <div class="row">
            <div class="col-xs-10 col-xs-offset-1 col-sm-8 col-sm-offset-2 col-md-4 col-md-offset-4">
                <div class="login-panel panel panel-default">
                    <div class="panel-heading">Inloggen</div>
                    <div class="result"></div>
                    <div class="panel-body">
                        <form role="form" id="loginForm">
                            <fieldset>
                                <div class="form-group">
                                    <input class="form-control" placeholder="Gebruikersnaam" name="username" type="text" autofocus="">
                                </div>
                                <div class="form-group">
                                    <input class="form-control" placeholder="Wachtwoord" name="password" type="password">
                                </div>

                                <div class="row">
                                    <div class="col-xs-7">
                                        <a href="#" class="btn btn-success post">Inloggen</a>
                                    </div>
                                </div>
                            </fieldset>
                        </form>
                    </div>
                </div>
            </div><!-- /.col-->
        </div><!-- /.row -->    
    </div>
    <footer class="footer">
        <div class="text-center">
            <p class="text-muted">&copy; <?php echo date("Y"); ?> company name</p>
        </div>
    </footer>



    <script src="js/jquery-1.11.1.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script type="text/javascript">

        $( document ).ready(function() {
            $('.result').hide();
            $(".post").on("click",function(){
                // console.log('clicked!');

                var formData = $('#loginForm').serialize();

                $.ajax({
                    type: "POST",
                    url: "checkauth.php",
                    data: $("#loginForm").serialize(), // serializes the form's elements.
                    success: function(data){
                        //window.location.href = "/welcome";
                        // console.log(data);
                         if(data.status2 == 'success'){
                            // 

                            $('.panel-body').fadeOut(1400);
                            $('.result').html(data.message);
                            $('.result').fadeIn(1200);
                            window.setTimeout(function() {
                                window.location.href = 'index.php';
                            }, 2000);

                        }else {
                            $('.result').html(data.message);
                        }
                    }
                });
             });
        });
    </script>
</body>

</html>

checkauth.php

<?php

session_start();

/* Check Login form submitted */    
    if($_SERVER['REQUEST_METHOD'] == 'POST'){
        header('Content-Type: application/json');

        /* Define username and associated password array */
        $logins = array('admin' => 'admin2',
                        'username1' => 'password1',
                        'username2' => 'password2');

        /* Check and assign submitted Username and Password to new variable */
        $Username = isset($_POST['username']) ? $_POST['username'] : '';
        $Password = isset($_POST['password']) ? $_POST['password'] : '';


        // print_r($_POST);

        /* Check Username and Password existence in defined array */        
        if (isset($logins[$Username]) && $logins[$Username] == $Password){
            /* Success: Set session variables and redirect to Protected page  */
            $_SESSION['UserData']['Username']=$logins[$Username];
            $_SESSION['UserData']['loggedin']=TRUE;

            $return['message'] =  '<br><div class="alert alert-success" role="alert">Login gegevens correct, welkom!</div><br>';
            $return['status2'] = 'success';

        } else {
            /*Unsuccessful attempt: Set error message */
            $return['message'] =  '<div class="alert alert-danger" role="alert">Incorrecte login gegevens. Probeer het aub. opnieuw.</div>';
            $return['status2'] = 'error';  

        }
        echo json_encode($return);
    }
    else{
        exit('No direct acces to this script!');
    }
?>

Can anyone help ?

  • 写回答

3条回答 默认 最新

  • duanshan1511 2015-06-08 07:28
    关注

    To make enter button to work you can use

    <input type="submit">
    

    Rather then

    <a href="#" class="btn btn-success post">Inloggen</a>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值