[英]After Validate (Same page) the value stay on the page
單擊“提交”(驗證)時,輸入(值)保持在同一頁面上
http://lab.iamrohit.in/cvalid/代碼
<form action="" method="post">
<select name="type">
<option value="American">American Express</option>
<option value="Dinners">Diner's Club</option>
<option value="Discover">Discover</option>
<option value="Master">Master Card</option>
<option value="Visa">Visa</option>
</select>
<input type="text" name="cNum">
<button type="submit">Submit</button>
</form>
單擊提交后,輸入保留在文本框中
您尚未在表單中指定操作,這就是表單默認提交到同一頁面的原因。 您可以使用autocomplete
。
自動完成允許瀏覽器預測值。 當用戶開始在字段中鍵入時,瀏覽器應根據先前鍵入的值顯示用於填充該字段的選項。
<input type="text" name="cNum" autocomplete="off">
如果您希望表單選擇的值在表單提交后選擇,請嘗試此操作
$type = '';
$cNum = '';
if(isset($_POST['submit'])){
$type = $_POST['type'];
$cNum = $_POST['cNum'];
}
?>
<form action="" method="post">
<select name="type">
<option value="American" <?php if($type == 'American'):?>selected="selected"<?php endif;?>>American Express</option>
<option value="Dinners" <?php if($type == 'Dinners'):?>selected="selected"<?php endif;?>>Diner's Club</option>
<option value="Discover" <?php if($type == 'Discover'):?>selected="selected"<?php endif;?>>Discover</option>
<option value="Master" <?php if($type == 'Master'):?>selected="selected"<?php endif;?>>Master Card</option>
<option value="Visa" <?php if($type == 'Visa'):?>selected="selected"<?php endif;?>>Visa</option>
</select>
<input type="text" name="cNum" value="<?php echo $cNum;?>"/>
<input type="submit" name="submit" value="submit"/>
</form>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.