通过$ _POST提交表单时,输入文件值仍然存在。像这样:
if($_POST){
$error = false;
if(!$post['price']){
$error = true;
$error_note['price'] = "*Should not be empty";
}
if($error == false){
//submit/save the data
}
}
<form name="post" id="post" method="post" action="">
<input name="price" value="<?=$_POST['price']?>" class="text-input" type="text" maxlength="15">
<select name="price-type" class="text-input">
<option value="" selected>Select price type</option>
<option value="item">Item</option>
<option value="kilo">Kilo</option>
<option value="rate">Rate</option>
</select>
<textarea class="description" name="description" cols="55%" rows="6"></textarea>
<button class="button" type="submit" name="submit-btn" >SUBMIT</button>
</form>
但我有textarea并在我的表单上选择输入。
如何在选择输入中保留textarea和所选项目的内容?
value="<?=$_POST['price']?>"
不起作用..
答案 0 :(得分:1)
检查这可能对您有所帮助
<form name="post" id="post" method="post" action="">
<input name="price" value="<?=isset($_POST['price']) ? $_POST['price'] : ''?>" class="text-input" type="text" maxlength="15">
<select name="price-type" class="text-input">
<option <?= (isset($_POST['price-type']) && $_POST['price-type']=='') ? 'selected' : '' ?> value="" >Select price type</option>
<option <?= (isset($_POST['price-type']) && $_POST['price-type']=='item') ? 'selected' : '' ?> value="item">Item</option>
<option <?= (isset($_POST['price-type']) && $_POST['price-type']=='kilo') ? 'selected' : '' ?> value="kilo">Kilo</option>
<option <?= (isset($_POST['price-type']) && $_POST['price-type']=='rate') ? 'selected' : '' ?> value="rate">Rate</option>
</select>
<textarea class="description" name="description" cols="55%" rows="6"><?=isset($_POST['description']) ? $_POST['description'] : '' ?></textarea>
<button class="button" type="submit" name="submit-btn" >SUBMIT</button>
</form>
答案 1 :(得分:0)
您已使用short tag
,但请注意您的短标记也应该为此
我建议总是使用php标签
value="<?php echo $_POST['price']; ?>"
要设置短标签,请执行此操作
short_open_tag=On //in php.ini
restart
Apache server.