javascript - 为什么不使用操作我的表单仍然将数据存储到数据库中

标签 javascript php jquery mysql

我正在考虑将 catcha 过程插入到表单中,所以我在考虑一些逻辑,所以我从谷歌下载了一个登录名,但我在这里不明白.. 为什么我的表单仍然使用 将数据存储到数据库中action=' ' 虽然它带有 action="register.php" 但正如我告诉过你的,我正在做一些逻辑工作所以你能告诉我这里有什么问题吗?

这是我的完整代码:

<?php
// show potential errors / feedback (from registration object)
if (isset($registration)) {
    if ($registration->errors) {
        foreach ($registration->errors as $error) {
            echo '<div class="alert-box error"><span>Error: </span>'.$error.'</div>';
        }
    }
    if ($registration->messages) {
        foreach ($registration->messages as $message) {
            echo '<div class="alert-box success"><span>Success: </span>'.$message.'</div>';
        }
    }
}
?>

<!DOCTYPE html>
<html>
    <head>
        <title>Registration with Linkvessel and collaborate with college's friends</title>
        <link rel='stylesheet' type='text/css' href="./CSS_files/registration_style.css" />
        <link rel="stylesheet" type="text/css" href="./bootstrap/css/bootstrap-responsive.css" />
        <link rel="stylesheet" type="text/css" href="./bootstrap/css/bootstrap-responsive.min.css"/>
        <link rel="stylesheet" type="text/css" href="./bootstrap/css/bootstrap.css" />
        <link rel="stylesheet" type="text/css" href="./bootstrap/css/bootstrap.min.css" />
        <link rel="stylesheet" type="text/css" href="./bootstrap/js/bootstrap.js" />
        <link rel="stylesheet" type="text/css" href="./bootstrap/js/bootstrap.min.js" />
         <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
        <script>
            $(function(){
                $("#datepicker").datepicker();
            });            
        </script>
        <style>
            .alert-box {
        color:#555;
        border-radius: 0px;
        font-family:Tahoma,Geneva,Arial,sans-serif; font-size:11px; font-size: 18px;
        padding:  30px 36px;
        margin:10px;
            }
            .alert-box span {
        font-weight:bold;
        text-transform:uppercase;
            }
            .error {
        border:2px solid #0c0b0b;
                background-color: #ff7e48;
            }

            .success{
            border:2px solid #0c0b0b;
            background-color: #a3ea42;
            }
        </style>
    </head>
    <body>
        <div id="header">
            <img id="logo_size" src="./images/logo.png" onmousedown="return false">
        </div><br><br><br>

        <form id="form_box" method="post" action='' name="registerform">
                <div id="title">
                    <h2>REGISTRATION FORM</h2>
                </div>

                <div class="controls pos_selectbox">
                    <select id="basic" name="user_college" class="input-medium">
                        <option>Select College</option>
                        <option>MAIIT kota</option>
                    </select>&nbsp; &nbsp;

                    <select id="basic" name="user_branch" class="input-medium">
                        <option>Select Branch</option>
                        <option>Computer science</option>
                        <option>Civil</option>
                        <option>Mechanical</option>
                        <option>Electrical</option>
                        <option>Bioinformatic</option>
                    </select>&nbsp; &nbsp;

                    <select id="basic" name="user_year" class="input-medium">
                        <option>Select year</option>
                        <option>1st year</option>
                        <option>2nd year</option>
                        <option>3rd year</option>
                        <option>4th year</option>
                        <option>Year completed</option>
                    </select>&nbsp; &nbsp;
                </div><br>

                <input id="input_pos" type="email" name="user_email" required="" placeholder="Email address" /><br><br>

                <input id="input_pos" type="password" name="user_password_new" required="" placeholder="Password" /><br><br>

                <input id="input_pos" type="password" name="user_password_repeat" required="" placeholder="Confirm password" /><br><br>

                <input id="name_pos" type="text" name="user_firstname" required="" placeholder="First name" />&nbsp;

                <input id="name_pos2" type="text" name="user_lastname" required="" placeholder="Last name" /><br><br>

                <input id="datepicker" type="text" name="user_dob" required="" placeholder="Date of birth" /><br><br>

                <input id="name_pos" type="text" name="user_state" required="" placeholder="State" />&nbsp;

                <input id="name_pos2" type="text" name="user_city" required="" placeholder="city" />&nbsp;<br><br>

                <input type="submit" name="register" id="pos_submit" class="btn btn-primary btn-large" value="Create account.."/>
            </form>
</html>

最佳答案

表单操作属性的空值默认为当前 URL。因此,如果该页面的 URL 是 register.php,则 action=''action='register.php' 相同。

W3C spec says this behavior is unspecified但是浏览器普遍实现了上述行为。

Finally, the encoded data is sent to the processing agent designated by the action attribute using the protocol specified by the method attribute.

This specification does not specify all valid submission methods or content types that may be used with forms. However, HTML 4 user agents must support the established conventions in the following cases:

  • If the method is "get" and the action is an HTTP URI, the user agent takes the value of action, appends a `?' to it, then appends the form data set, encoded using the "application/x-www-form-urlencoded" content type. The user agent then traverses the link to this URI. In this scenario, form data are restricted to ASCII codes.

  • If the method is "post" and the action is an HTTP URI, the user agent conducts an HTTP "post" transaction using the value of the action attribute and a message created according to the content type specified by the enctype attribute.

For any other value of action or method, behavior is unspecified.

关于javascript - 为什么不使用操作我的表单仍然将数据存储到数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24121749/

相关文章:

PHP/MYSQL : data isn't appearing on the table

PHP 脚本中 echo 内的 JavaScript 函数未调用

jquery - 将 onclick 属性值保存到变量中然后执行

javascript - 在 <head> 中包含样式表会产生与 javascript 附加到 head 不同的结果

javascript - 禁用然后启用按钮,禁用为 false 但在页面上它们仍然处于禁用状态

JavaScript - 如何拆分二维数组中的字符串?

javascript - for in Controller 中的循环

javascript - 在从异步函数内部调用函数时,是否有任何理由更喜欢 node.js 中函数的异步版本?

javascript - 在JS中从json文件接收信息

php - SimpleXMLElement 在 600dpi 背景上返回 null