我的HTML表单未提交。我正在尝试将数据从表单收集到API,但是表单未提交。
<div class="col-lg-12">
<div class="card">
<div class="panel panel-primary">
<div class="panel-header">
<h4 class="text-center">Investment Preview</h4>
</div>
<div class="panel-body">
<h5 class="text-center"> Credit your account </h5>
<?php $classObj->funding(); ?>
<form action="google.com" method="POST">
<p class="form-control-static text-center"> Enter amount in dollar </p>
<div class="input-group">
<span class="input-group-addon">$</span>
<input type="number" name="amount" min="300" max="4999" class="form-control" required />
</div>
</div>
<div class="panel-footer">
<button type="submit" name="fund" class="btn btn-primary btn-block btn-flat"> Invest </button>
</div>
</form>
</div>
</div>
</div>
这是用于筹款方法的php代码
function funding(){
echo "testing";
if(isset($_POST["fund"])) {
$amount = mysqli_real_escape_string($this->conn, trim($_POST['amount']));
echo $amount;
}
}
答案 0 :(得分:2)
它没有提交,因为您的表单操作为google.com
<form action="google.com" method="POST">
这需要更改为包含处理代码的正确文件路径。
答案 1 :(得分:0)
您的HTML标记未正确嵌套。表单中的第二个</div>
与<div>
之前的<form>
匹配,因此它也结束了表单。结果,提交按钮不在表单内。
在</div>
之后将</form>
向下移动。
任何体面的编辑器或IDE都应该警告您有关标签不平衡的问题。您还应该注意到,当打开浏览器控制台并检查DOM检查器时,该按钮不在表单内。
<div class="col-lg-12">
<div class="card">
<div class="panel panel-primary">
<div class="panel-header">
<h4 class="text-center">Investment Preview</h4>
</div>
<div class="panel-body">
<h5 class="text-center"> Credit your account </h5>
<?php $classObj->funding(); ?>
<form action="yourscript.php" method="POST">
<p class="form-control-static text-center"> Enter amount in dollar </p>
<div class="input-group">
<span class="input-group-addon">$</span>
<input type="number" name="amount" min="300" max="4999" class="form-control" required />
</div>
<div class="panel-footer">
<button type="submit" name="fund" class="btn btn-primary btn-block btn-flat"> Invest </button>
</div>
</form>
</div>
</div>
</div>
</div>
答案 2 :(得分:0)
这是表单的打开和关闭错误,请在表单提交完成后进行如下设置:
<div class="col-lg-12">
<div class="card">
<div class="panel panel-primary">
<div class="panel-header">
<h4 class="text-center">Investment Preview</h4>
</div>
<form action="https://www.google.com" method="POST">
<div class="panel-body">
<h5 class="text-center"> Credit your account </h5>
<?php $classObj->funding(); ?>
<p class="form-control-static text-center"> Enter amount in dollar </p>
<div class="input-group">
<span class="input-group-addon">$</span>
<input type="number" name="amount" min="300" max="4999" class="form-control" required />
</div>
</div>
<div class="panel-footer">
<button type="submit" name="fund" class="btn btn-primary btn-block btn-flat"> Invest </button>
</div>
</form>
</div>
</div>