在回显POST值时出错

时间:2013-04-09 13:01:04

标签: php

这是我的代码,所有<input>标记的问题,任何人都可以告诉我这是集成HTML和PHP的正确方法

<div style="width:115px; padding-top:10px;float:left;" align="left">Email Address:</div>
<div style="width:300px;float:left;" align="left">

<input type="text" name="email" id="email" value="<?php echo strip_tags($_POST["email"]); ?>"     class="vpb_textAreaBoxInputs"></div><br clear="all"><br clear="all">

2 个答案:

答案 0 :(得分:2)

您需要确保在使用之前设置$_POST["email"],因为您可以使用isset()

<?php if(isset($_POST["email"])) { echo strip_tags($_POST["email"]); }else{echo 'default' ;} ?>

答案 1 :(得分:0)

使用ternary operator显示每个input的默认值

<input type="text" name="email" id="email" value="<?php echo isset($_POST['email'])?strip_tags($_POST['email']):''; ?>" class="vpb_textAreaBoxInputs"></div><br clear="all"><br clear="all">

firstname

相同
<input type="text" name="firstname" id="firstname" value="<?php echo isset($_POST['firstname'])?strip_tags($_POST['firstname']):''; ?>" > 
相关问题