隐藏的表单域将起作用。但是,如果您决定改用 PHP 会话,请查看此处。
从上面的链接...
<?php
// page1.php
session_start();
echo 'Welcome to page #1';
$_SESSION['favcolor'] = 'green';
$_SESSION['animal'] = 'cat';
$_SESSION['time'] = time();
// Works if session cookie was accepted
echo '<br /><a href="page2.php">page 2</a>';
// Or maybe pass along the session id, if needed
echo '<br /><a href="page2.php?' . SID . '">page 2</a>';
?>
查看 page1.php 后,第二个页面 page2.php 将包含会话数据。阅读会话参考以获取有关传播会话 id的信息,例如,它解释了常量 SID 的全部含义。
<?php
// page2.php
session_start();
echo 'Welcome to page #2<br />';
echo $_SESSION['favcolor']; // green
echo $_SESSION['animal']; // cat
echo date('Y m d H:i:s', $_SESSION['time']);
// You may want to use SID here, like we did in page1.php
echo '<br /><a href="page1.php">page 1</a>';
?>
更新
从您的代码片段来看,我相信您会通过执行以下操作来设置会话变量:
<form action="" method="post">
<select type="select" name="servicearea" >
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
<option value="option3">Option 3</option>
</select>
<input type="submit" name="Submit" value="Submit!" />
</form>
<?php
session_start();
if (isset($_POST['Submit'])) {
$_SESSION['optionValue'] = $_POST['servicearea'];
}
echo $_SESSION['optionValue'];
?>