HTML表格未提交数据?
有人知道为什么我的HTML表格不提交任何东西吗?一旦我单击“提交”按钮,它无能为力?不知道发生了什么事,检查了一切,无法让我围绕它?如果有人可能有一个主意,那真的很有帮助,谢谢!
<div class="row">
<div class="col-md-6">
<div class="alert alert-success hidden" id="contactSuccess">
<strong>Success!</strong> Your message has been sent to us.
</div>
<div class="alert alert-danger hidden" id="contactError">
<strong>Error!</strong> There was an error sending your message.
</div>
<form name="register" action="register.php" id="contactForm" type="POST">
<div class="row">
<div class="form-group">
<div class="col-md-6">
<label>First name *</label>
<input type="text" value="" data-msg-required="Please enter your first name." maxlength="100" class="form-control" name="first_name" id="name">
</div>
<div class="col-md-6">
<label>Last name *</label>
<input type="text" value="" data-msg-required="Please enter your last name." maxlength="100" class="form-control" name="last_name" id="name">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-md-12">
<label>Your email address *</label>
<input type="email" value="" data-msg-required="Please enter your email address." data-msg-email="Please enter a valid email address." maxlength="100" class="form-control" name="email_address" id="email">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-md-6">
<label>Username *</label>
<input type="text" value="" data-msg-required="Please enter a valid username." maxlength="100" class="form-control" name="username" id="name">
</div>
<div class="col-md-6">
<label>Contact Number *</label>
<input type="number" value="" data-msg-required="Please enter your mobile number." maxlength="100" class="form-control" name="mobile" id="name">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-md-6">
<label>Date of birth *</label>
<br>
<fieldset class="date">
<select id="date1" name="date1" />
<option>1</option>
<option>2</option>
<option>…</option>
</select>
<select id="date2" name="date2" />
<option>Jan</option>
<option>Feb</option>
<option>Mar</option>
</select>
<select id="date3" name="date3" />
<option>1905</option>
<option>1906</option>
</select>
</fieldset>
</div>
<div class="col-md-6">
<label>Contact Number *</label>
<input type="radio" name="gender" value="Male">Male
<input type="radio" name="gender" value="Female">Female
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<input type="submit" name="Submit" value="Register" class="btn btn-lg btn-primary">
</div>
</div>
</form>
</div>
我正在使用我的网站上的联系表的副本作为注册表格,因为它看起来好多了,也许这是原因之一?
请登录。按要求:
<?
include 'core/init.php';
// Define post fields into simple variables
$first_name = mysql_real_escape_string($_POST['first_name']);
$last_name = mysql_real_escape_string($_POST['last_name']);
$email_address = mysql_real_escape_string($_POST['email_address']);
$username = mysql_real_escape_string($_POST['username']);
$mobile = $_POST['mobile'];
$gender = $_POST['gender'];
$date1 = $_POST['date1'];
$date2 = $_POST['date2'];
$date3 = $_POST['date3'];
/* Let's strip some slashes in case the user entered
any escaped characters. */
$first_name = stripslashes($first_name);
$last_name = stripslashes($last_name);
$email_address = stripslashes($email_address);
$username = stripslashes($username);
$gender = stripslashes($gender);
/* Do some error checking on the form posted fields */
if((!$first_name) || (!$last_name) || (!$email_address) || (!$gender) || (!$username)){
if(!$first_name){
header('Location: signup.php?signuperror=2');
}
if(!$last_name){
header('Location: signup.php?signuperror=3');
}
if(!$email_address){
header('Location: signup.php?signuperror=4');
}
if(!$username){
header('Location: signup.php?signuperror=5');
}
if(!$gender){
header('Location: signup.php?signuperror=6');
}
include "signup.php"; // Show the form again!
/* End the error checking and if everything is ok, we'll move on to
creating the user account */
exit(); // if the error checking has failed, we'll exit the script!
}
/* Let's do some checking and ensure that the user's email address or username
does not exist in the database */
$sql_email_check = mysql_query("SELECT email_address FROM users WHERE email_address='$email_address'");
$sql_username_check = mysql_query("SELECT username FROM users WHERE username='$username'");
$email_check = mysql_num_rows($sql_email_check);
$username_check = mysql_num_rows($sql_username_check);
if(($email_check > 0) || ($username_check > 0)){
if($email_check > 0){
header('Location: signup.php?signuperror=7');
unset($email_address);
}
if($username_check > 0){
header('Location: signup.php?signuperror=8');
unset($username);
}
include 'signup.php'; // Show the form again!
exit(); // exit the script so that we do not create this account!
}
/* Everything has passed both error checks that we have done.
It's time to create the account! */
/* Random Password generator.
http://www.phpfreaks.com/quickcode/Random_Password_Generator/56.php
We'll generate a random password for the
user and encrypt it, email it and then enter it into the db.
*/
function makeRandomPassword() {
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
srand((double)microtime()*1000000);
$i = 0;
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($salt, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
$random_password = makeRandomPassword();
$db_password = md5($random_password);
// Enter info into the Database.
$info2 = htmlspecialchars($info);
$sql = mysql_query("INSERT INTO users (first_name, last_name, email_address, username, password, gender, date1, date2, date3, signup_date, mobile)
VALUES('$first_name', '$last_name', '$email_address', '$username', '$db_password', '$gender', '$date1', '$date2', '$date3', now(), '$mobile')") or die (mysql_error());
if(!$sql){
header('Location: signup.php?signuperror=9');
} else {
$userid = mysql_insert_id();
// Let's mail the user!
$subject = "BaseCentre Members";
$message = "Dear $first_name $last_name,
Thank you for registering at BaseCentre, http://www.basecentre.co.uk/
You are two steps away from logging in and accessing our exclusive entertainment.
To activate your membership, please click here: http://www.basecentre.co.uk/activate.php?id=$userid&code=$db_password
Once you activate your memebership, you will be able to login with the following information:
Username: $username
Password: $random_password
Thanks!
Base Admin Team.
This is an automated response, please do not reply!";
mail($email_address, $subject, $message, "From: BaseCentre Members<[email protected]>\nX-Mailer: PHP/" . phpversion());
////// MAIL ADMIN
$subject2 = "BaseCentre New User!";
$message2 = "Dear Admin,
This is a message to alert you that a new user has signed up to BaseCentre.
You can view all details of the new member and all other members direct from the admin control panel at http://basecentre.co.uk/admin.php
Here are the details of the new registered user:
Username: $username
Email Address: $email_address
Thanks!
BaseCentre Automation.
This is an automated response, please do not reply!";
mail('[email protected]', $subject2, $message2, "From: BaseCentre Members<[email protected]>\nX-Mailer: PHP/" . phpversion());
header('Location: login.php?loginerror=6');
include 'login.php';
}
?>
JS脚本以供参考:
/*
Name: View - Contact
Written by: Okler Themes - (http://www.okler.net)
Version: 2.0
*/
(function() {
"use strict";
var Contact = {
initialized: false,
initialize: function() {
if (this.initialized) return;
this.initialized = true;
this.build();
this.events();
},
build: function() {
this.validations();
},
events: function() {
},
validations: function() {
$("#contactForm").validate({
submitHandler: function(form) {
// Loading State
var submitButton = $(this.submitButton);
submitButton.button("loading");
// Ajax Submit
$.ajax({
type: "POST",
url: "php/contact-form.php",
data: {
"name": $("#contactForm #name").val(),
"email": $("#contactForm #email").val(),
"subject": $("#contactForm #subject").val(),
"message": $("#contactForm #message").val()
},
dataType: "json",
success: function (data) {
if (data.response == "success") {
$("#contactSuccess").removeClass("hidden");
$("#contactError").addClass("hidden");
// Reset Form
$("#contactForm .form-control")
.val("")
.blur()
.parent()
.removeClass("has-success")
.removeClass("has-error")
.find("label.error")
.remove();
if(($("#contactSuccess").position().top - 80) < $(window).scrollTop()){
$("html, body").animate({
scrollTop: $("#contactSuccess").offset().top - 80
}, 300);
}
} else {
$("#contactError").removeClass("hidden");
$("#contactSuccess").addClass("hidden");
if(($("#contactError").position().top - 80) < $(window).scrollTop()){
$("html, body").animate({
scrollTop: $("#contactError").offset().top - 80
}, 300);
}
}
},
complete: function () {
submitButton.button("reset");
}
});
},
rules: {
name: {
required: true
},
email: {
required: true,
email: true
},
subject: {
required: true
},
message: {
required: true
}
},
highlight: function (element) {
$(element)
.parent()
.removeClass("has-success")
.addClass("has-error");
},
success: function (element) {
$(element)
.parent()
.removeClass("has-error")
.addClass("has-success")
.find("label.error")
.remove();
}
});
}
};
Contact.initialize();
})();
Does anyone have an idea of why my HTML form does not submit anything? Once I click the submit button it does nothing? No idea what is going on, have checked everything and can't get my head around it? If anyone might have an idea, it would be really helpful, thanks!
<div class="row">
<div class="col-md-6">
<div class="alert alert-success hidden" id="contactSuccess">
<strong>Success!</strong> Your message has been sent to us.
</div>
<div class="alert alert-danger hidden" id="contactError">
<strong>Error!</strong> There was an error sending your message.
</div>
<form name="register" action="register.php" id="contactForm" type="POST">
<div class="row">
<div class="form-group">
<div class="col-md-6">
<label>First name *</label>
<input type="text" value="" data-msg-required="Please enter your first name." maxlength="100" class="form-control" name="first_name" id="name">
</div>
<div class="col-md-6">
<label>Last name *</label>
<input type="text" value="" data-msg-required="Please enter your last name." maxlength="100" class="form-control" name="last_name" id="name">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-md-12">
<label>Your email address *</label>
<input type="email" value="" data-msg-required="Please enter your email address." data-msg-email="Please enter a valid email address." maxlength="100" class="form-control" name="email_address" id="email">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-md-6">
<label>Username *</label>
<input type="text" value="" data-msg-required="Please enter a valid username." maxlength="100" class="form-control" name="username" id="name">
</div>
<div class="col-md-6">
<label>Contact Number *</label>
<input type="number" value="" data-msg-required="Please enter your mobile number." maxlength="100" class="form-control" name="mobile" id="name">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-md-6">
<label>Date of birth *</label>
<br>
<fieldset class="date">
<select id="date1" name="date1" />
<option>1</option>
<option>2</option>
<option>…</option>
</select>
<select id="date2" name="date2" />
<option>Jan</option>
<option>Feb</option>
<option>Mar</option>
</select>
<select id="date3" name="date3" />
<option>1905</option>
<option>1906</option>
</select>
</fieldset>
</div>
<div class="col-md-6">
<label>Contact Number *</label>
<input type="radio" name="gender" value="Male">Male
<input type="radio" name="gender" value="Female">Female
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<input type="submit" name="Submit" value="Register" class="btn btn-lg btn-primary">
</div>
</div>
</form>
</div>
I am using a copy of the contact form on my site for the registration form as it looks so much better, maybe this is one of the reasons ?
Register.php as requested:
<?
include 'core/init.php';
// Define post fields into simple variables
$first_name = mysql_real_escape_string($_POST['first_name']);
$last_name = mysql_real_escape_string($_POST['last_name']);
$email_address = mysql_real_escape_string($_POST['email_address']);
$username = mysql_real_escape_string($_POST['username']);
$mobile = $_POST['mobile'];
$gender = $_POST['gender'];
$date1 = $_POST['date1'];
$date2 = $_POST['date2'];
$date3 = $_POST['date3'];
/* Let's strip some slashes in case the user entered
any escaped characters. */
$first_name = stripslashes($first_name);
$last_name = stripslashes($last_name);
$email_address = stripslashes($email_address);
$username = stripslashes($username);
$gender = stripslashes($gender);
/* Do some error checking on the form posted fields */
if((!$first_name) || (!$last_name) || (!$email_address) || (!$gender) || (!$username)){
if(!$first_name){
header('Location: signup.php?signuperror=2');
}
if(!$last_name){
header('Location: signup.php?signuperror=3');
}
if(!$email_address){
header('Location: signup.php?signuperror=4');
}
if(!$username){
header('Location: signup.php?signuperror=5');
}
if(!$gender){
header('Location: signup.php?signuperror=6');
}
include "signup.php"; // Show the form again!
/* End the error checking and if everything is ok, we'll move on to
creating the user account */
exit(); // if the error checking has failed, we'll exit the script!
}
/* Let's do some checking and ensure that the user's email address or username
does not exist in the database */
$sql_email_check = mysql_query("SELECT email_address FROM users WHERE email_address='$email_address'");
$sql_username_check = mysql_query("SELECT username FROM users WHERE username='$username'");
$email_check = mysql_num_rows($sql_email_check);
$username_check = mysql_num_rows($sql_username_check);
if(($email_check > 0) || ($username_check > 0)){
if($email_check > 0){
header('Location: signup.php?signuperror=7');
unset($email_address);
}
if($username_check > 0){
header('Location: signup.php?signuperror=8');
unset($username);
}
include 'signup.php'; // Show the form again!
exit(); // exit the script so that we do not create this account!
}
/* Everything has passed both error checks that we have done.
It's time to create the account! */
/* Random Password generator.
http://www.phpfreaks.com/quickcode/Random_Password_Generator/56.php
We'll generate a random password for the
user and encrypt it, email it and then enter it into the db.
*/
function makeRandomPassword() {
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
srand((double)microtime()*1000000);
$i = 0;
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($salt, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
$random_password = makeRandomPassword();
$db_password = md5($random_password);
// Enter info into the Database.
$info2 = htmlspecialchars($info);
$sql = mysql_query("INSERT INTO users (first_name, last_name, email_address, username, password, gender, date1, date2, date3, signup_date, mobile)
VALUES('$first_name', '$last_name', '$email_address', '$username', '$db_password', '$gender', '$date1', '$date2', '$date3', now(), '$mobile')") or die (mysql_error());
if(!$sql){
header('Location: signup.php?signuperror=9');
} else {
$userid = mysql_insert_id();
// Let's mail the user!
$subject = "BaseCentre Members";
$message = "Dear $first_name $last_name,
Thank you for registering at BaseCentre, http://www.basecentre.co.uk/
You are two steps away from logging in and accessing our exclusive entertainment.
To activate your membership, please click here: http://www.basecentre.co.uk/activate.php?id=$userid&code=$db_password
Once you activate your memebership, you will be able to login with the following information:
Username: $username
Password: $random_password
Thanks!
Base Admin Team.
This is an automated response, please do not reply!";
mail($email_address, $subject, $message, "From: BaseCentre Members<[email protected]>\nX-Mailer: PHP/" . phpversion());
////// MAIL ADMIN
$subject2 = "BaseCentre New User!";
$message2 = "Dear Admin,
This is a message to alert you that a new user has signed up to BaseCentre.
You can view all details of the new member and all other members direct from the admin control panel at http://basecentre.co.uk/admin.php
Here are the details of the new registered user:
Username: $username
Email Address: $email_address
Thanks!
BaseCentre Automation.
This is an automated response, please do not reply!";
mail('[email protected]', $subject2, $message2, "From: BaseCentre Members<[email protected]>\nX-Mailer: PHP/" . phpversion());
header('Location: login.php?loginerror=6');
include 'login.php';
}
?>
JS Script for reference:
/*
Name: View - Contact
Written by: Okler Themes - (http://www.okler.net)
Version: 2.0
*/
(function() {
"use strict";
var Contact = {
initialized: false,
initialize: function() {
if (this.initialized) return;
this.initialized = true;
this.build();
this.events();
},
build: function() {
this.validations();
},
events: function() {
},
validations: function() {
$("#contactForm").validate({
submitHandler: function(form) {
// Loading State
var submitButton = $(this.submitButton);
submitButton.button("loading");
// Ajax Submit
$.ajax({
type: "POST",
url: "php/contact-form.php",
data: {
"name": $("#contactForm #name").val(),
"email": $("#contactForm #email").val(),
"subject": $("#contactForm #subject").val(),
"message": $("#contactForm #message").val()
},
dataType: "json",
success: function (data) {
if (data.response == "success") {
$("#contactSuccess").removeClass("hidden");
$("#contactError").addClass("hidden");
// Reset Form
$("#contactForm .form-control")
.val("")
.blur()
.parent()
.removeClass("has-success")
.removeClass("has-error")
.find("label.error")
.remove();
if(($("#contactSuccess").position().top - 80) < $(window).scrollTop()){
$("html, body").animate({
scrollTop: $("#contactSuccess").offset().top - 80
}, 300);
}
} else {
$("#contactError").removeClass("hidden");
$("#contactSuccess").addClass("hidden");
if(($("#contactError").position().top - 80) < $(window).scrollTop()){
$("html, body").animate({
scrollTop: $("#contactError").offset().top - 80
}, 300);
}
}
},
complete: function () {
submitButton.button("reset");
}
});
},
rules: {
name: {
required: true
},
email: {
required: true,
email: true
},
subject: {
required: true
},
message: {
required: true
}
},
highlight: function (element) {
$(element)
.parent()
.removeClass("has-success")
.addClass("has-error");
},
success: function (element) {
$(element)
.parent()
.removeClass("has-error")
.addClass("has-success")
.find("label.error")
.remove();
}
});
}
};
Contact.initialize();
})();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
如果您的表格没有提交,并且您已经在上一个答案中检查了建议,则可能是您具有多个表单结尾标签,重叠的表单标签或一些错误的封闭div元素。
这是一个清单,如果您仍然遇到问题,您可能会查看其他内容:
检查您有一个有效的“操作”属性您的表格标签
例如:
action =“/主题”
检查您具有有效的'方法'属性(不是'类型'属性)
例如:
method =“ post”
打开和关闭
&lt; form&gt;
标签和放置在这些标签中的提交按钮。确保没有错误关闭的div元素。 - 仔细检查一下,因为它是许多头痛的最常见原因重叠形式标签。 (确保您没有多个表格关闭标签等)
post正在发送,但是后端/服务器/API中没有将错误或成功消息返回浏览器的错误? (检查开发人员工具中浏览器的'网络'部分(Windows快捷方式:
f12
)如果您的问题仍然发生,请考虑尝试使用JavaScript而不是HTML表单提交。代码>事件到按钮并编写表单。您可以调试整个功能::)
最终知道您的问题。
If your form is not submitting and you have checked the suggestions in the previous answers then its likely that you have multiple form ending tags, overlapping form tags or some incorrectly closed div elements.
Here's a checklist, additional things you could have a look at in case you still experience the problem:
Check you have a valid 'action' attribute your form tag
eg:
action="/subjects"
Check you have a valid 'method' attribute (not a 'type' attribute)
eg:
method="post"
Opening and closing
<form>
tags and a submit button placed within these tags. Make sure that there are no incorrectly closed div elements. - DOUBLE CHECK THIS AS IT IS THE MOST COMMON CAUSE OF MANY HEADACHESOverlapping Form tags. (Make sure that you don't have multiple form closing tags, etc)
post is being sent but there is an error in the backend/server/api which is not returning an error or success message to the browser? (Check 'Network' section of browser in Developer Tools (windows shortcut:
F12
)If your problem still happens then consider trying to use javascript instead of html form submission. By adding an
onclick
event to a button and writing the form.submit function. This way you can debug the entire thing :)Curious to know of your problem in the end.
表单的有效属性是
方法
不是type
method ='post'
The valid attribute for the form is
method
nottype
method = 'post'
确保您在每个字段上都有属性名称。
示例:名称=“电子邮件”
Make sure that you have the attribute name on each field.
Example: name="email"
很简单:
type =“ post”
用method =“ post”
更改is simple :
type="POST"
change withMethod="POST"
另外,请检查您的操作=“ register.php”未被重定向。
例如,
action =“/xyz/register.php” - register.php
应在'xyz'文件夹中。如果
regissh.php
不在“ XYZ”文件夹中,并且表格正在重定向,则将转到正确的页面,但会丢失表单的值(名称,电子邮件等)。Also check that your action="register.php" is not being redirected.
For example
action="/xyz/register.php" -- register.php
should be in the 'xyz' folder.If
register.php
is not in the 'xyz' folder and the form is being redirected, it will go to the correct page but lose the form's values (name, email etc).除邮政方法外,输入字段还应具有名称属性。
As well as the post method, input fields should also have a name attribute.
更改此行,
您必须使用
method =“ post”
而不是type =“ post”
Change this line,
you must use
method="POST"
instead oftype="POST"
确保您提交按钮是类型提交而不是类型按钮。
Make sure you submit button is of type submit rather than type button.