2017-06-27 47 views
-2

我想僅在提交後顯示輸入的文本。文本框將不可見。我想顯示我的輸入和文本框將被刪除,同時在php

  <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> 
+3

而.......你怎麼試試? –

+0

看到這個:http://www.dreamincode.net/forums/topic/240512-showhide-values-in-input-text-box/ – Dexter

+0

提交後,我想只顯示文本的文本框不可見。我應該使用什麼? – saharabanana

回答

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"即可。

如果您還有任何疑問或某些不適用的問題,請隨時詢問。 :)

+0

@saharabanana不客氣:) – Twinfriends

+0

但我仍然需要onsbumit,因爲我會添加一個函數,它會自動添加我的號碼。不起作用? – saharabanana

+0

你是什麼意思與「添加我的號碼」? – Twinfriends

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> 
+0

其實我做到了。我正在做這件事。這更復雜。我只是創建一個簡單的例子。但你用任何方式幫助我:) – saharabanana

+0

​​<?php if(isset($ _ POST ['submit'])){echo $ _POST ['txtDate1'];} else {echo「「;}?>這不適用於我的表單 – saharabanana

+0

它不起作用,因爲您的輸入字段有語法錯誤。你寫了'';' – Twinfriends

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> 
+0

@Twinfriends你能檢查嗎? – saharabanana

+0

什麼是不工作?你能更精確一點嗎?告訴我什麼是錯誤的。你有錯誤信息嗎?空白頁?究竟發生了什麼?我真的很期待幫助你,但我需要更多信息:) – Twinfriends

+0

沒有錯誤,但我想要的是一個輸出,在用戶輸入並單擊提交按鈕後不顯示文本框。我發佈的代碼仍在顯示文本框 – saharabanana

相關問題