php - 为什么我的表单输入提交不可点击?

标签 php html css forms

我不知道是什么导致了这个问题。我有一个注册表单,但每当我尝试单击“完成注册”按钮时,都没有任何反应!表格甚至没有提交!这是 HTML:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" name="viewport" content="width=device-width, height=device-height, initial-scale = 1">
        <title>Signup</title>
        <link rel="icon" href="/images/favicon.ico" type="image/x-icon">
        <link rel="stylesheet" href="/styling/signupstyle.css">
    </head>

    <body>
        <div id="formdiv" method="post">
            <h1 id="title">Sign Up Here!</h1>
            <form id="form" name="signupform" onsubmit="return false;">
                <div class="inputdiv">
                    <label for="username">Username: </label>
                    <input name="username" type="text" maxlength="20">
                    <span id="unamestatus"></span>
                </div>
                <div class="inputdiv">
                    <label for="password">Password: </label>
                    <input type="password" name="pass1" maxlength="20">
                </div>
                <div class="inputdiv">
                    <label for="pass2">Confirm Password: </label>
                    <input type="password" name="pass2" maxlength="20">
                </div>
                <div class="inputdiv">
                    <label for="email">Email: </label>
                    <input name="email" type="text" maxlength="100">
                </div>
                <div class="inputdiv">
                    <label for="gender">Gender: </label>
                    <select name="gender"">
                        <option value=""></option>
                        <option value="m">Male</option>
                        <option value"f">Female</option>
                    </select>
                </div>
                <div class="inputdiv">
                    <label for="country">Country: </label>
                    <select name="country">
                        <?php include_once("countries.html"); ?>
                    </select>
                </div>
                <div>
                    <input id="submit" type="submit" name="submit" value="Complete Registration!" style="width: 40%; font-size: 25px; padding: 1% 0;">
                </div>
                <div style="margin-top: 5%;">
                    <img src="/images/ConnectionLogo.PNG" alt="Connection" style="width: 25%; height: 25%;">
                </div>
            </form>
        </div>
    </body>

</html>

这是表单的样式:

body {
width: 100vw;
height: 100vh;
font-size: 25px;
background: linear-gradient(to right, #3DCBF2 , #3DF2D4);
overflow-x: hidden;
overflow-y: hidden;
}

#formdiv {
margin: auto;
width: 50%;
height: 85%;
border: 5px solid #2A67EB;
background-color: #37A3F0;
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
}

#form {
width: 70%;
margin: 0 auto;
text-align: center;
height: 90%;
}

#title {
text-align: center;
color: #57E7F7;
margin-top: 1%;
}

#form input {
width: 35%;
font-size: 20px;
background-color: #70D1FA;
border: 3px solid #4187E8;
color: #376BE6;
}

#form select {
width: 25%;
font-size: 20px;
background-color: #70D1FA;
border: 3px solid #4187E8;
color: #376BE6;
}

.inputdiv {
padding-bottom: 5%;
}

#form label {
margin-right: 3%;
color: #3544F0;
font-weight: bold;
}

这是尚未完成的 PHP,但肯定不会导致问题:

if ($_POST['submit']) {
// Receiving data from the form // 
$username = preg_replace('#[^a-z0-9]#i', '', $_POST['username']);
$usercheck = mysqli_query($connection, "SELECT * FROM users WHERE username='$username'");
$password = mysqli_real_escape_string($connection, $_POST['pass1']);
$passconfirm = mysqli_real_escape_string($connection, $_POST['pass2']);
$email = mysqli_real_escape_string($connection, $_POST['email']);
$emailcheck = filter_var($email, FILTER_VALIDATE_EMAIL);
$emailcheck2 = mysqli_query($connnection, "SELECT * FROM users WHERE email='$email'");
$gender = mysqli_real_escape_string($connection, $_POST['gender']);
$country = mysqli_real_escape_string($connection, $_POST['country']);
// Now for the check functions //
if ($usercheck != 0) {
    die("Sorry, your username is already in use! Redirecting...");
};
if ($password != $passwordconfirm) {
    die("The passwords do not match! Redirecting...");
};
if ($emailcheck != 0) {
    die("That email is already in use! Redirecting...");
};

};

最佳答案

因为您明确取消了提交操作。你说 onsubmit="return false;"。当您明确告诉它什么都不做时,您期望它做什么?

此外,旁注,您有一些 HTML 问题:

<select name="gender"">
    <option value=""></option>
    <option value="m">Male</option>
    <option value"f">Female</option>

应该是:

<select name="gender">
    <option value=""></option>
    <option value="m">Male</option>
    <option value="f">Female</option>

关于php - 为什么我的表单输入提交不可点击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36531683/

相关文章:

php - JSONLint 和 PHP JSON_DECODE 之间的差异

php - 是否可以使用 Fpdf 生成 Pdf 设计

javascript - 使表行 TR 成为链接

javascript - 在 JSON 数组 Javascript 中访问 JSON 对象

html - Paper.js VS EaselJS VS Fabric.js VS KineticJS

html - 为什么我的背景图片不显示?

php - 以条件为参数的函数问题

javascript - Colorbox的tabindex =“-1”属性可防止在表单字段上进行焦点和键入

html - &lt;input&gt; 框不断下降到带有 float : right 的下一行

css - 放置在 "div"元素中时不显示 Img