问题遇到的现象和发生背景
是这样的,最近用bootstrap写了几个表单都出现了这个问题,点击submit按钮都没有任何反应。
但是神奇的是昨天用bootstrap写了个登陆注册页面却可以提交了!我老老实实对比了俩表单的区别,该加的都加上了,还是不行。
这是表单的代码,我把无关紧要的style都去了
<?php
require_once('./conn.php');
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!-- Bootstrap core CSS -->
<link href="./assets/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="https://fonts.googleapis.com/css?family=Playfair+Display:700,900&display=swap" rel="stylesheet">
<!-- 帖子的形式 -->
<link rel="canonical" href="https://getbootstrap.com/docs/5.1/examples/masonry/">
</head>
<script>
function chkIssue(form) {
if (form.title.value == "") {
alert("请输入标题!");
form.title.select();
return (false);
}
if (form.content.value == "") {
alert("请输入正文!");
form.content.select();
return (false);
}
return (true);
}
</script>
<body>
<div class="issue">
<h2 class="h2Title">发布内容</h2>
<form action="issueSubmit.php" method="POST" class="form2" onSubmit="return chkIssue(this)">
<div class="selectType">
<input type="radio" value="star" name="type" class="form-check-input" id="exampleRadio1">
<label class="form-check-label" for="exampleRadio1">1</label>
<input type="radio" value="pet" name="type" class="form-check-input" id="exampleRadio2">
<label class="form-check-label" for="exampleRadio2">2</label>
<input type="radio" value="reading" name="type" class="form-check-input" id="exampleRadio3">
<label class="form-check-label" for="exampleRadio3">3</label>
</div>
<div class="downTwo">
<div class="input-group mb-3 title">
<span class="input-group-text" id="basic-addon1">标题</span>
<input type="text" class="form-control" name="title" id="title">
</div>
<div class="input-group content">
<span class="input-group-text">正文</span>
<textarea class="form-control" name="content" id="content"></textarea>
</div>
</div>
<input type="file" class="form-control image" id="image" name="image">
<button type="submit" id="btn5" class="btn btn-primary submitBtn" name="btn5">提交</button>
</form>
</div>
<script src="./assets/dist/js/bootstrap.bundle.min.js"></script>
<script async src="https://cdn.jsdelivr.net/npm/masonry-layout@4.2.2/dist/masonry.pkgd.min.js" integrity="sha384-GNFwBvfVxBkLMJpYMOABq3c+d3KnQxudP/mGPkzpZSTYykLBNsZEnG2D9G/X/+7D" crossorigin="anonymous"></script>
<script src="./js/cheatsheet.js"></script>
</body>
</html>
大概长这样
然后下面是php的处理代码issueSubmit.php
<!DOCTYPE html>
<?php
require_once('conn.php');
?>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<?php
session_start();
$name = $_SESSION['nickname'];
$time = date('Y-m-d');
$title = $_POST['title'];
$type = $_POST['type'];
$content = $_POST['content'];
// echo $table;
if ($type == 'comics') {
$tag = "1";
}
if ($type == 'pet') {
$tag = "2";
}
if ($type == 'star') {
$tag = "3";
}
//获取表的记录数作为id
$sql0 = mysqli_query($conn, "select count(*) as re from posts");
$result0 = mysqli_fetch_array($sql0);
$newid = $result0['re'] * 1 + 1000 + 1;
$default0 = 0;
$sql = "insert into posts values($newid,'$tag','$title','$content','$name','$time',$default0,'')";
mysqli_query($conn, $sql);
// header("location:welcome.php");
echo "<script language='javascript'>alert('发表成功');history.back();</script>";
?>
</body>
</html>
我尝试过的方法包括但不限于:
- button的id不要设置为“submit”
- 删除button的name属性
- 把所有的input的加上name属性
- form加上onsubmit事件
- form加上 enctype="multipart/form-data"
- 每个input的name和id一一对应
都无济于事……我个人认为是form这边有什么神秘的力量阻挡了数据的post……