在用户输入数据详细信息之前,如何默认填写结果。 例如我的PHP代码就像这样
<b>Address:</b> <?php echo htmlentities($dnn['you_address'], ENT_QUOTES, 'UTF-8'); ?>
如果在用户填写地址格式之前,如何显示默认信息。 例如
地址:地址尚未添加
答案 0 :(得分:0)
使用Javascript或Jquery。如果仅使用PHP,则在运行提交表单后将获得结果。 如果要在运行提交表单之前显示结果。你可以使用Javascript,如下面的提醒。
<script>
function check(){
if(document.getElementById('address').value==''){
alert("Address has not added");
}
在您的地址输入中,提供id = "address"
和onkeypress="check()"
答案 1 :(得分:0)
您可以简单地使用占位符!
<input type="text" name="you_address" placeholder="Address has not added" value="<?php echo htmlentities($dnn['you_address'], ENT_QUOTES, 'UTF-8'); ?>" />
答案 2 :(得分:0)
在此PHP Fiddle - 点击“运行”或F9执行 - 就像这样
<?php
$defVal = 'default input';
?>
<form action="" method="POST">
<input type="text" name="test-input" value="<?php echo $defVal?>">
<input type="submit" value="submit" name="submit">
</form>
<?php
if(isset($_POST['submit'])){
echo $_POST['test-input'];
}
?>