PHP에서 전송 후 선택 상자의 값 유지하기
사용자의 선택이 제출 후에도 유지되도록 만들어 봅시다:
<form action="" method="GET">
<select name="test">
<option value="1" <?php
if (!empty($_GET['test']) and $_GET['test'] === '1') {
echo 'selected';
}
?>>item1</option>
<option value="2" <?php
if (!empty($_GET['test']) and $_GET['test'] === '2') {
echo 'selected';
}
?>>item2</option>
<option value="3" <?php
if (!empty($_GET['test']) and $_GET['test'] === '3') {
echo 'selected';
}
?>>item3</option>
</select>
<input type="submit">
</form>
이전 작업을 수정하여 제출 후 선택한 값이 사라지지 않도록 하세요.