gpt4 book ai didi

javascript - 文本区域和选择输入的数据或值保留

转载 作者:行者123 更新时间:2023-12-03 05:42:15 24 4
gpt4 key购买 nike

通过 $_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>

关于javascript - 文本区域和选择输入的数据或值保留,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40481095/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com