繁体   English   中英

验证(同一页面)后,值留在页面上

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM