通过$_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>
但我有文本区域,并在我的表格上选择输入。
如何在选择输入时保留文本区域和所选项目的内容value="<?=$_POST['price']?>"
对此不起作用。
检查一下它可能会帮助你
<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>
您已经使用了short tag
,但请注意,您的短标签也应该为此打开
我建议始终使用php标签
value="<?php echo $_POST['price']; ?>"
要设置短标签打开,请执行此
short_open_tag=On //in php.ini
和restart
你的Apache server.