html
  • forms
  • 2012-08-23 66 views 0 likes 
    0

    我在.php中有一個類似於下面的表單。無論何時用戶在列表框中選擇或在我的表單的文本框中輸入任何內容,當他們點擊提交時,它會在加載和檢索數據後重置所選值。我想至少保留選定的值直到他們離開頁面。如何在php/html中保留文本框選定的值

    <form action = "samefile.php" method = "post"> 
    Enter Start Date <input type = '"text" name = "startdate" >  </br> 
    Enter End Date <input type = "'text" name = "enddate" >  </br> 
    Enter Organisation Name <input type = 'text" name = "organisation" >  </br> 
    submit <input type = '"submit" value = "Fetch Data" >  </br> 
    </form> 
    
    +0

    爲此,您應該學習Javascript。 – kapa

    +0

    也許你應該閱讀一些關於PHP中表單處理的知識。 http://php.net/manual/en/tutorial.forms.php – HerrSerker

    回答

    1

    只不過是迴應後值:

    <input type="text" name="startdate" value="<?php echo isset($_POST['startdate']) ? htmlspecialchars($_POST['startdate']) : '' ?>" /> 
    

    請記住用htmlspecialchars()避免代碼注入。

    +1

    你真的很想用'htmlspecialchars($ _ POST ['startdate'])'。永遠不要忘記逃避用戶輸入! – flyx

    +0

    @ sujanth ..我只是注意到..這個代碼不能用於列表框..我用下面的