<?php
if(isset($_POST['submit'])){
// Here the code captures the inputs that entered.
Based on the inputs the script shows the associated information.
}
<form method="POST">
<input type="text" name="postc">
<input type="text" name="nr">
<button name="submit">Send</button>
</form>
如何检查两个输入是否已填满,以及是否填充它们会自动加载PHP代码以获取数据。 (我是初学者)
我希望我解释得对!
示例页面
答案 0 :(得分:2)
我建议如下:
<强> HTML 强>
<form method="POST" name="myForm" action="page.php">
<input type="text" name="postc" onchange="submitForm()">
<input type="text" name="nr" onchange="submitForm()">
</form>
<强>的Javascript 强>
只要您填写表单输入,就会调用此函数。它提供了获取输入值并仅在填写所有(在本例中)输入时动态提交表单。
function submitForm() {
var postc = document.forms["myForm"]["postc"].value;
var nr = document.forms["myForm"]["nr"].value;
if (postc != "" && nr != "")
document.myForm.submit();
}
修改强>
这是一个完整的工作示例
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Your title</title>
<script>
function submitForm() {
var postc = document.forms["myForm"]["postc"].value;
var nr = document.forms["myForm"]["nr"].value;
if (postc != "" && nr != "") {
document.myForm.submit();
}
}
</script>
</head>
<body>
<form method="POST" name="myForm" action="#">
<input type="text" name="postc" onchange="submitForm()">
<input type="text" name="nr" onchange="submitForm()">
</form>
<?php
if(isset($_POST['postc'])){
echo "postc value: " . $_POST['postc'] . '<br />';
echo "nr value: " . $_POST['nr'];
}
?>
</body>
</html>
希望这会有所帮助: - )