基本上,程序是用户输入月份的数字,例如: 12,然后如果您单击提交按钮,它将显示月份的名称,在本例中为12月。
问题是每次我单击submit时,textbox中的值都消失了,我希望textbox中仍然包含"12“,即使在单击submit按钮之后。
附言:不要介意非英语单词。
<form method = "post">
4. Insert month(1-12) :
<input type="text" name="monthTxt" value=""><br/>
<input type="submit" value="Submit">
</form>
<?php
$monthTemp = $_POST["monthTxt"];
$testing = $monthTemp;
function bulan($bulan)
{
$months = array(1 => 'Januari', 2 => 'Februari', 3 => 'Maret', 4 => 'April', 5 => 'Mei', 6 => 'Juni', 7 => 'Juli', 8 => 'Agustus', 9 => 'September', 10 => 'Oktober', 11 => 'November', 12 => 'December');
if($bulan < 1 || $bulan > 12)
{
echo "Input tidak boleh kurang dari 0, lebih dari 12, atau huruf";
}
else
{
echo $months[$bulan];
}
}
bulan($monthTemp);
?>
发布于 2015-07-06 15:41:11
如果不将此全部更改为AJAX,则需要在表单中包含POST
变量(如果已设置)。将表单域的value属性更改为以下值:
<input type="text" name="monthTxt" value="<?php if (isset($_POST['monthTxt'])) { echo $_POST['monthTxt']; } ?>">
https://stackoverflow.com/questions/31240187
复制相似问题