我想在提交后才显示输入的文字。文本框将不可见。
<head><title>some title</title></head>
<body>
<form method="post" action="">
<input type="text" name="something" value="<?php
if(isset($_POST['submit'])) {echo ($_POST['something']);}?>" />
<input type="submit" name="submit" />
</form>
</body>
<html>
答案 0 :(得分:0)
你几乎自己实现了......你有你的控制结构,所以我不确定你是否自己编写代码,因为如果你能够这样做直到现在,你也应该是能够为您的问题找到解决方案。无论如何,如上所述,只需使用IF-Else语句,只有在未提交的情况下才打印整个表格。
<html>
<head>
<title>Some title</title>
</head>
<body>
<?php
if(isset($_POST["submit"])) {
echo $_POST["something"];
}
else {
echo'
<form method="POST">
<input type="text" name="something">
<input type="submit" name="submit" Value="Send">
</form>';
}
?>
</body>
</html>
答案 1 :(得分:0)
<script type="text/javascript">
function onSubmitButton(){
document.getElementById('submitButtonDiv').style.display = "block";
document.getElementById('progressBar').style.display = "none";
return false;
}
</script>
<body>
<form name="expense_report" method="POST" onSubmit="return onSubmitButton()" action="sample.php">
<div align=center id="submitButtonDiv" >
<table border=1>
<tr>
<td><?php if(isset($_POST['submit'])) {echo $_POST['txtDate1'];}else {echo '<input type="text" name="txtDate1" size="7" id="datepicker" maxlength="20">';}?></td>
<td><?php if(isset($_POST['submit'])) {echo $_POST['txtOR1'];}else{echo '<input type="text" name="txtOR1" size="15" maxlength="20">';}?></td>
<td><?php if(isset($_POST['submit'])) {echo $_POST['txtTin1'];}else{ echo '<input type="text" name="txtTin1" size="15" maxlength="20">';}?></td>
<td><?php if(isset($_POST['submit'])) {echo $_POST['txtPart1'];}else{ echo '<input type="text" name="txtPart1" size="50" maxlength="80">';}?></td>
<td align=right><?php if(isset($_POST['submit'])) {echo $_POST['txtAmt1'];}else{ echo '<input type="text" name="txtAmt1" size="12" maxlength="20" onChange="add_amount(this.form)">';}?></td>
</tr></table>
</div>
<div align=center id="progressBar" style="display:block">
<input type="submit" name="submit" />
<input type=reset>
</div>
</body>
答案 2 :(得分:0)
因此。既然我现在明白你尝试了什么,这里是你实际尝试的代码:
<body>
<form name="expense_report" method="POST">
<div align=center id="submitButtonDiv" >
<table border=1>
<tr>
<td><?php if(isset($_POST['submit'])) {echo $_POST['txtDate1'];}else {echo '<input type="text" name="txtDate1" size="7" id="datepicker" maxlength="20">';}?></td>
<td><?php if(isset($_POST['submit'])) {echo $_POST['txtOR1'];}else{echo '<input type="text" name="txtOR1" size="15" maxlength="20">';}?></td>
<td><?php if(isset($_POST['submit'])) {echo $_POST['txtTin1'];}else{ echo '<input type="text" name="txtTin1" size="15" maxlength="20">';}?></td>
<td><?php if(isset($_POST['submit'])) {echo $_POST['txtPart1'];}else{ echo '<input type="text" name="txtPart1" size="50" maxlength="80">';}?></td>
<td align=right><?php if(isset($_POST['submit'])) {echo $_POST['txtAmt1'];}else{ echo '<input type="text" name="txtAmt1" size="12" maxlength="20" onChange="add_amount(this.form)">';}?></td>
</tr>
</table>
</div>
<?php
if(empty($_POST['submit'])) {
echo'
<div align=center id="progressBar" style="display:block">
<input type="submit" name="submit" />
<input type=reset>
</div>';
}
?>
</form>
</body>
我测试过,它有效。好吧,我删除了Javascript部分,但由于没有任何必要的内容(你可以用普通的PHP做任何事情)我觉得很好。
请注意,您不能同时拥有onSubmit
功能和action=""
。如您所见,自从发布到页面本身后,我删除了onSubmit
以及action=""
。如果要将数据发布到另一个脚本,只需在表单标题中添加action="link_to_script.php"
动作。
如果您仍有任何问题或某些问题无效,请随时提出。 :)