如何存储和调用会话变量中最后单击的单选按钮
我试图找出根据用户单击的单选按钮显示文本的最佳方式。我在使用会话来执行此操作时遇到问题。当我使用以下代码时,仅显示与第一次单击的单选按钮相关的信息(例如,如果有人单击单选按钮“A”,然后改变主意并单击单选按钮“B”,则会话似乎认为“A”仍然被点击。
有什么建议吗?
这是 HTML:
<div class="radio">
<label for="choice1">Choice 1</label>
<input class="selection" id="choice1" type="radio" name="selection" value="choice1"/>
<div class="radio">
<label for="choice2">Choice 2</label>
<input class="selection" id="choice2" type="radio" name="selection" value="choice2" />
</div>
这是 PHP 代码:
if (!isset($_SESSION)) {
session_start();
$_SESSION['formStarted'] = true;
//...
if(($_SESSION['selection']) == 'choice1'){echo 'Text to be included only if choice 1 was selected.';}
I'm trying to figure out the best way to display text based on which radio button a user has clicked. I am having trouble using sessions to do this. When I use the following code, only the information related to the radio button that was first clicked is displayed (e.g., if someone clicks on radion button "A," then changes his mind and clicks on radio button "B," the session seems to think "A" is still clicked.
Any suggestions?
Here's the HTML:
<div class="radio">
<label for="choice1">Choice 1</label>
<input class="selection" id="choice1" type="radio" name="selection" value="choice1"/>
<div class="radio">
<label for="choice2">Choice 2</label>
<input class="selection" id="choice2" type="radio" name="selection" value="choice2" />
</div>
Here's the PHP code:
if (!isset($_SESSION)) {
session_start();
$_SESSION['formStarted'] = true;
//...
if(($_SESSION['selection']) == 'choice1'){echo 'Text to be included only if choice 1 was selected.';}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
或 $_GET 或 $_REQUEST
OR $_GET or $_REQUEST